MCPcopy Create free account
hub / github.com/defold/defold / socket_send

Function socket_send

engine/script/src/luasocket/wsocket.c:195–218  ·  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

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

Callers 1

meth_sendFunction · 0.70

Calls 1

socket_waitfdFunction · 0.70

Tested by

no test coverage detected