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

Function socket_send

engine/script/src/luasocket/usocket.c:202–229  ·  view source on GitHub ↗

-------------------------------------------------------------------------*\ * Send with timeout \*-------------------------------------------------------------------------*/

Source from the content-addressed store, hash-verified

200* Send with timeout
201\*-------------------------------------------------------------------------*/
202int socket_send(p_socket ps, const char *data, size_t count,
203 size_t *sent, p_timeout tm)
204{
205 int err;
206 *sent = 0;
207 /* avoid making system calls on closed sockets */
208 if (*ps == SOCKET_INVALID) return IO_CLOSED;
209 /* loop until we send something or we give up on error */
210 for ( ;; ) {
211 long put = (long) send(*ps, data, count, 0);
212 /* if we sent anything, we are done */
213 if (put >= 0) {
214 *sent = put;
215 return IO_DONE;
216 }
217 err = errno;
218 /* EPIPE means the connection was closed */
219 if (err == EPIPE) return IO_CLOSED;
220 /* we call was interrupted, just try again */
221 if (err == EINTR) continue;
222 /* if failed fatal reason, report error */
223 if (err != EAGAIN) return err;
224 /* wait until we can send something or we timeout */
225 if ((err = socket_waitfd(ps, WAITFD_W, tm)) != IO_DONE) return err;
226 }
227 /* can't reach here */
228 return IO_UNKNOWN;
229}
230
231/*-------------------------------------------------------------------------*\
232* Sendto with timeout

Callers

nothing calls this directly

Calls 1

socket_waitfdFunction · 0.70

Tested by

no test coverage detected