<tr><thcolspan="2">Enumerator</th></tr><tr><tdclass="fieldname"><aid="gga98b099cf8c1c7e38ad78501f270e193da80e8f169fda236c56bfb795ed62903db"></a>LWS_WRITE_TEXT </td><tdclass="fielddoc"><p>Send a ws TEXT message,the pointer must have LWS_PRE valid memory behind it. The receiver expects only valid utf-8 in the payload </p>
<tr><tdclass="fieldname"><aid="gga98b099cf8c1c7e38ad78501f270e193daf6486c0dba50c44198100717721d9ab2"></a>LWS_WRITE_BINARY </td><tdclass="fielddoc"><p>Send a ws BINARY message, the pointer must have LWS_PRE valid memory behind it. Any sequence of bytes is valid </p>
<tr><tdclass="fieldname"><aid="gga98b099cf8c1c7e38ad78501f270e193da10047eb05b5e1c298151dc47a5b44826"></a>LWS_WRITE_CONTINUATION </td><tdclass="fielddoc"><p>Continue a previous ws message, the pointer must have LWS_PRE valid memory behind it </p>
<tr><tdclass="fieldname"><aid="gga98b099cf8c1c7e38ad78501f270e193dafe5a38e940ce56708ac814627e9c0917"></a>LWS_WRITE_HTTP_HEADERS </td><tdclass="fielddoc"><p>Send http headers (http2 encodes this payload and LWS_WRITE_HTTP payload differently, http 1.x links also handle this correctly. so to be compatible with both in the future,header response part should be sent using this regardless of http version expected) </p>
<tr><tdclass="fieldname"><aid="gga98b099cf8c1c7e38ad78501f270e193da115440f272a5d55518adfc8099acfee3"></a>LWS_WRITE_NO_FIN </td><tdclass="fielddoc"><p>This part of the message is not the end of the message </p>
<tr><tdclass="fieldname"><aid="gga98b099cf8c1c7e38ad78501f270e193da220d8e8652d9b97fb66e476e2a60ffce"></a>LWS_WRITE_CLIENT_IGNORE_XOR_MASK </td><tdclass="fielddoc"><p>client packet payload goes out on wire unmunged only useful for security tests since normal servers cannot decode the content if used </p>
<p><aclass="el"href="group__sending-data.html#gafd5fdd285a0e25ba7e3e1051deec1001">lws_write()</a> - Apply protocol then write data to client </p><dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramname">wsi</td><td>Websocket instance (available from user callback) </td></tr>
<tr><tdclass="paramname">buf</td><td>The data to send. For data being sent on a websocket connection (ie, not default http), this buffer MUST have LWS_PRE bytes valid BEFORE the pointer. This is so the protocol header data can be added in-situ. </td></tr>
<tr><tdclass="paramname">len</td><td>Count of the data bytes in the payload starting from buf </td></tr>
<tr><tdclass="paramname">protocol</td><td>Use LWS_WRITE_HTTP to reply to an http connection, and one of LWS_WRITE_BINARY or LWS_WRITE_TEXT to send appropriate data on a websockets connection. Remember to allow the extra bytes before and after buf if LWS_WRITE_BINARY or LWS_WRITE_TEXT are used.</td></tr>
</table>
</dd>
</dl>
<p>This function provides the way to issue data back to the client for both http and websocket protocols.</p>
<p>the send buffer has to have LWS_PRE bytes valid BEFORE the buffer pointer you pass to <aclass="el"href="group__sending-data.html#gafd5fdd285a0e25ba7e3e1051deec1001">lws_write()</a>.</p>
<p>This allows us to add protocol info before and after the data, and send as one packet on the network without payload copying, for maximum efficiency.</p>
<p>So for example you need this kind of code to use lws_write with a 128-byte payload</p>
<p>char buf[LWS_PRE + 128];</p>
<p>// fill your part of the buffer... for example here it's all zeros memset(&buf[LWS_PRE], 0, 128);</p>
<p>there is no protocol data prepended, and don't need to take care about the LWS_PRE bytes valid before the buffer pointer.</p>
<p>LWS_PRE is at least the frame nonce + 2 header + 8 length LWS_SEND_BUFFER_POST_PADDING is deprecated, it's now 0 and can be left off. The example apps no longer use it.</p>
<p>Pad LWS_PRE to the CPU word size, so that word references to the address immediately after the padding won't cause an unaligned access error. Sometimes for performance reasons the recommended padding is even larger than sizeof(void *). </p><preclass="fragment"> In the case of sending using websocket protocol, be sure to allocate
valid storage before and after buf as explained above. This scheme
allows maximum efficiency of sending data and protocol in a single
packet while not burdening the user code with any protocol knowledge.
Return may be -1 for a fatal error needing connection close, or the
number of bytes sent.
</pre><h1>Truncated Writes </h1>
<p>The OS may not accept everything you asked to write on the connection.</p>
<p>Posix defines POLLOUT indication from poll() to show that the connection will accept more write data, but it doesn't specifiy how much. It may just accept one byte of whatever you wanted to send.</p>
<p>LWS will buffer the remainder automatically, and send it out autonomously.</p>
<p>During that time, WRITABLE callbacks will be suppressed.</p>
<p>This is to handle corner cases where unexpectedly the OS refuses what we usually expect it to accept. You should try to send in chunks that are almost always accepted in order to avoid the inefficiency of the buffering. </p>