MCPcopy Create free account
hub / github.com/Tencent/UnLua / socket_send

Function socket_send

Plugins/UnLuaExtensions/LuaSocket/Source/src/wsocket.cpp:201–224  ·  view source on GitHub ↗

-------------------------------------------------------------------------*\ * Send with timeout * On windows, if you try to send 10MB, the OS will buffer EVERYTHING * this can take an awful lot of time and we will end up blocked. * Therefore, whoever calls this function should not pass a huge buffer. \*-------------------------------------------------------------------------*/

Source from the content-addressed store, hash-verified

199* Therefore, whoever calls this function should not pass a huge buffer.
200\*-------------------------------------------------------------------------*/
201int socket_send(p_socket ps, const char *data, size_t count,
202 size_t *sent, p_timeout tm)
203{
204 int err;
205 *sent = 0;
206 /* avoid making system calls on closed sockets */
207 if (*ps == SOCKET_INVALID) return IO_CLOSED;
208 /* loop until we send something or we give up on error */
209 for ( ;; ) {
210 /* try to send something */
211 int put = send(*ps, data, (int) count, 0);
212 /* if we sent something, we are done */
213 if (put > 0) {
214 *sent = put;
215 return IO_DONE;
216 }
217 /* deal with failure */
218 err = WSAGetLastError();
219 /* we can only proceed if there was no serious error */
220 if (err != WSAEWOULDBLOCK) return err;
221 /* avoid busy wait */
222 if ((err = socket_waitfd(ps, WAITFD_W, tm)) != IO_DONE) return err;
223 }
224}
225
226/*-------------------------------------------------------------------------*\
227* Sendto with timeout

Callers

nothing calls this directly

Calls 1

socket_waitfdFunction · 0.70

Tested by

no test coverage detected