Navigation


Changeset 201:1b47afa59358 in freeDiameter


Ignore:
Timestamp:
Feb 10, 2010, 11:22:42 AM (14 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Also timeout on sends

Location:
freeDiameter
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • freeDiameter/cnxctx.c

    r199 r201  
    507507        tv.tv_sec = 3;  /* allow 3 seconds timeout for TLS session cleanup */
    508508        CHECK_SYS_DO( setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)), /* best effort only */ );
     509        CHECK_SYS_DO( setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)), /* Also timeout for sending, to avoid waiting forever */ );
    509510}       
    510511
     
    533534static ssize_t fd_cnx_s_send(struct cnxctx * conn, void *buffer, size_t length)
    534535{
    535         return send(conn->cc_socket, buffer, length, 0);
     536        ssize_t ret = 0;
     537        int timedout = 0;
     538again:
     539        ret = send(conn->cc_socket, buffer, length, 0);
     540        /* Handle special case of timeout */
     541        if ((ret < 0) && (errno == EAGAIN)) {
     542                if (!conn->cc_closing)
     543                        goto again; /* don't care, just ignore */
     544                if (!timedout) {
     545                        timedout ++; /* allow for one timeout while closing */
     546                        goto again;
     547                }
     548                CHECK_SYS_DO(ret, /* continue */);
     549        }
     550       
     551        return ret;
    536552}
    537553
     
    12361252                        CHECK_GNUTLS_DO( ret = fd_tls_send_handle_error(conn, conn->cc_tls_para.session, buf + sent, len - sent), return ENOTCONN );
    12371253                } else {
    1238                         CHECK_SYS( ret = send(conn->cc_socket, buf + sent, len - sent, 0) ); /* better to replace with sendmsg for atomic sending? */
     1254                        CHECK_SYS( ret = fd_cnx_s_send(conn, buf + sent, len - sent) ); /* better to replace with sendmsg for atomic sending? */
    12391255                }
    12401256                sent += ret;
     
    12721288                        } else {
    12731289                                if (!conn->cc_tls) {
    1274                                         CHECK_FCT( fd_sctp_sendstr(conn->cc_socket, conn->cc_sctp_para.next, buf, len) );
     1290                                        CHECK_FCT( fd_sctp_sendstr(conn->cc_socket, conn->cc_sctp_para.next, buf, len, &conn->cc_closing) );
    12751291                                } else {
    12761292                                        /* push the record to the appropriate session */
  • freeDiameter/cnxctx.h

    r194 r201  
    103103int fd_sctp_get_remote_ep(int sock, struct fd_list * list);
    104104int fd_sctp_get_str_info( int sock, uint16_t *in, uint16_t *out, sSS *primary );
    105 int fd_sctp_sendstr(int sock, uint16_t strid, uint8_t * buf, size_t len);
     105int fd_sctp_sendstr(int sock, uint16_t strid, uint8_t * buf, size_t len, int * cc_closing);
    106106int fd_sctp_recvmeta(int sock, uint16_t * strid, uint8_t ** buf, size_t * len, int *event, int * cc_closing);
    107107
  • freeDiameter/sctp.c

    r196 r201  
    10421042
    10431043/* Send a buffer over a specified stream */
    1044 int fd_sctp_sendstr(int sock, uint16_t strid, uint8_t * buf, size_t len)
     1044int fd_sctp_sendstr(int sock, uint16_t strid, uint8_t * buf, size_t len, int * cc_closing)
    10451045{
    10461046        struct msghdr mhdr;
     
    10511051        } anci;
    10521052        ssize_t ret;
    1053        
    1054         TRACE_ENTRY("%d %hu %p %zd", sock, strid, buf, len);
     1053        int timedout = 0;
     1054       
     1055        TRACE_ENTRY("%d %hu %p %zd %p", sock, strid, buf, len, cc_closing);
     1056        CHECK_PARAMS(cc_closing);
    10551057       
    10561058        memset(&mhdr, 0, sizeof(mhdr));
     
    10781080       
    10791081        TRACE_DEBUG(FULL, "Sending %db data on stream %hu of socket %d", len, strid, sock);
    1080        
    1081         CHECK_SYS( ret = sendmsg(sock, &mhdr, 0) );
     1082again: 
     1083        ret = sendmsg(sock, &mhdr, 0);
     1084        /* Handle special case of timeout */
     1085        if ((ret < 0) && (errno == EAGAIN)) {
     1086                if (!*cc_closing)
     1087                        goto again; /* don't care, just ignore */
     1088                if (!timedout) {
     1089                        timedout ++; /* allow for one timeout while closing */
     1090                        goto again;
     1091                }
     1092        }
     1093       
     1094        CHECK_SYS( ret );
    10821095        ASSERT( ret == len ); /* There should not be partial delivery with sendmsg... */
    10831096       
  • freeDiameter/sctps.c

    r194 r201  
    166166        CHECK_PARAMS_DO( tr && data, { errno = EINVAL; return -1; } );
    167167       
    168         CHECK_FCT_DO( fd_sctp_sendstr(ctx->parent->cc_socket, ctx->strid, (uint8_t *)data, len), /* errno is already set */ return -1 );
     168        CHECK_FCT_DO( fd_sctp_sendstr(ctx->parent->cc_socket, ctx->strid, (uint8_t *)data, len, &ctx->parent->cc_closing), /* errno is already set */ return -1 );
    169169       
    170170        return len;
Note: See TracChangeset for help on using the changeset viewer.