libwebsockets
Lightweight C library for HTML5 websockets
lws-write.h
1 /*
2  * libwebsockets - small server side websockets and web server implementation
3  *
4  * Copyright (C) 2010-2018 Andy Green <andy@warmcat.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation:
9  * version 2.1 of the License.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301 USA
20  *
21  * included from libwebsockets.h
22  */
23 
29 #if !defined(LWS_SIZEOFPTR)
30 #define LWS_SIZEOFPTR ((int)sizeof (void *))
31 #endif
32 
33 #if defined(__x86_64__)
34 #define _LWS_PAD_SIZE 16 /* Intel recommended for best performance */
35 #else
36 #define _LWS_PAD_SIZE LWS_SIZEOFPTR /* Size of a pointer on the target arch */
37 #endif
38 #define _LWS_PAD(n) (((n) % _LWS_PAD_SIZE) ? \
39  ((n) + (_LWS_PAD_SIZE - ((n) % _LWS_PAD_SIZE))) : (n))
40 /* last 2 is for lws-meta */
41 #define LWS_PRE _LWS_PAD(4 + 10 + 2)
42 /* used prior to 1.7 and retained for backward compatibility */
43 #define LWS_SEND_BUFFER_PRE_PADDING LWS_PRE
44 #define LWS_SEND_BUFFER_POST_PADDING 0
45 
46 #define LWS_WRITE_RAW LWS_WRITE_HTTP
47 
48 /*
49  * NOTE: These public enums are part of the abi. If you want to add one,
50  * add it at where specified so existing users are unaffected.
51  */
52 enum lws_write_protocol {
53  LWS_WRITE_TEXT = 0,
58  LWS_WRITE_BINARY = 1,
63  LWS_WRITE_CONTINUATION = 2,
66  LWS_WRITE_HTTP = 3,
69  /* LWS_WRITE_CLOSE is handled by lws_close_reason() */
70  LWS_WRITE_PING = 5,
71  LWS_WRITE_PONG = 6,
72 
73  /* Same as write_http but we know this write ends the transaction */
74  LWS_WRITE_HTTP_FINAL = 7,
75 
76  /* HTTP2 */
77 
78  LWS_WRITE_HTTP_HEADERS = 8,
84  LWS_WRITE_HTTP_HEADERS_CONTINUATION = 9,
88  /****** add new things just above ---^ ******/
89 
90  /* flags */
91 
92  LWS_WRITE_BUFLIST = 0x20,
100  LWS_WRITE_NO_FIN = 0x40,
103  LWS_WRITE_H2_STREAM_END = 0x80,
108  LWS_WRITE_CLIENT_IGNORE_XOR_MASK = 0x80
112 };
113 
114 /* used with LWS_CALLBACK_CHILD_WRITE_VIA_PARENT */
115 
117  struct lws *wsi;
118  unsigned char *buf;
119  size_t len;
120  enum lws_write_protocol wp;
121 };
122 
123 
212 LWS_VISIBLE LWS_EXTERN int
213 lws_write(struct lws *wsi, unsigned char *buf, size_t len,
214  enum lws_write_protocol protocol);
215 
216 /* helper for case where buffer may be const */
217 #define lws_write_http(wsi, buf, len) \
218  lws_write(wsi, (unsigned char *)(buf), len, LWS_WRITE_HTTP)
219 
231 static LWS_INLINE int
232 lws_write_ws_flags(int initial, int is_start, int is_end)
233 {
234  int r;
235 
236  if (is_start)
237  r = initial;
238  else
239  r = LWS_WRITE_CONTINUATION;
240 
241  if (!is_end)
242  r |= LWS_WRITE_NO_FIN;
243 
244  return r;
245 }
246 
260 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
261 lws_raw_transaction_completed(struct lws *wsi);
262 
Definition: lws-write.h:116