~ubuntu-branches/ubuntu/trusty/luasocket/trusty

« back to all changes in this revision

Viewing changes to src/usocket.c

  • Committer: Bazaar Package Importer
  • Author(s): Enrico Tassi
  • Date: 2007-12-27 02:03:37 UTC
  • mfrom: (3.1.5 hardy)
  • Revision ID: james.westby@ubuntu.com-20071227020337-dch6u5sztqwj8l97
Tags: 2.0.2-3
* Renamed luasocket-doc.docs to liblua-socket-doc.docs so that
  documentation is ipart of the package (Closes: #457891)
* Added Vcs-Browser and removed XS-X- from Vcs-Svn
* Bumped Standards-Version to 3.7.3
* Placed -dev and -doc packages in the right sections
* Added documentation to every dpatch patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
* The penalty of calling select to avoid busy-wait is only paid when
7
7
* the I/O call fail in the first place. 
8
8
*
9
 
* RCS ID: $Id: usocket.c,v 1.36 2005/11/22 08:33:29 diego Exp $
 
9
* RCS ID: $Id: usocket.c,v 1.37 2007/06/11 23:44:54 diego Exp $
10
10
\*=========================================================================*/
11
11
#include <string.h> 
12
12
#include <signal.h>
206
206
        size_t *sent, p_timeout tm)
207
207
{
208
208
    int err;
 
209
    *sent = 0;
209
210
    /* avoid making system calls on closed sockets */
210
211
    if (*ps == SOCKET_INVALID) return IO_CLOSED;
211
212
    /* loop until we send something or we give up on error */
212
 
    *sent = 0;
213
213
    for ( ;; ) {
214
214
        long put = (long) send(*ps, data, count, 0);
215
215
        /* if we sent anything, we are done */
239
239
        SA *addr, socklen_t len, p_timeout tm)
240
240
{
241
241
    int err;
 
242
    *sent = 0;
242
243
    if (*ps == SOCKET_INVALID) return IO_CLOSED;
243
 
    *sent = 0;
244
244
    for ( ;; ) {
245
245
        long put = (long) sendto(*ps, data, count, 0, addr, len);  
246
246
        if (put > 0) {
261
261
\*-------------------------------------------------------------------------*/
262
262
int socket_recv(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm) {
263
263
    int err;
 
264
    *got = 0;
264
265
    if (*ps == SOCKET_INVALID) return IO_CLOSED;
265
266
    for ( ;; ) {
266
267
        long taken = (long) recv(*ps, data, count, 0);
269
270
            return IO_DONE;
270
271
        }
271
272
        err = errno;
272
 
        *got = 0;
273
273
        if (taken == 0) return IO_CLOSED;
274
274
        if (err == EINTR) continue;
275
275
        if (err != EAGAIN) return err; 
284
284
int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got, 
285
285
        SA *addr, socklen_t *len, p_timeout tm) {
286
286
    int err;
 
287
    *got = 0;
287
288
    if (*ps == SOCKET_INVALID) return IO_CLOSED;
288
289
    for ( ;; ) {
289
290
        long taken = (long) recvfrom(*ps, data, count, 0, addr, len);
292
293
            return IO_DONE;
293
294
        }
294
295
        err = errno;
295
 
        *got = 0;
296
296
        if (taken == 0) return IO_CLOSED;
297
297
        if (err == EINTR) continue;
298
298
        if (err != EAGAIN) return err; 
359
359
        case ECONNREFUSED: return "connection refused";
360
360
        case ECONNABORTED: return "closed";
361
361
        case ECONNRESET: return "closed";
362
 
        case ETIMEDOUT: return "timedout";
 
362
        case ETIMEDOUT: return "timeout";
363
363
        default: return strerror(errno);
364
364
    }
365
365
}