Changeset 201:1b47afa59358 in freeDiameter
- Timestamp:
- Feb 10, 2010, 11:22:42 AM (14 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- freeDiameter
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
freeDiameter/cnxctx.c
r199 r201 507 507 tv.tv_sec = 3; /* allow 3 seconds timeout for TLS session cleanup */ 508 508 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 */ ); 509 510 } 510 511 … … 533 534 static ssize_t fd_cnx_s_send(struct cnxctx * conn, void *buffer, size_t length) 534 535 { 535 return send(conn->cc_socket, buffer, length, 0); 536 ssize_t ret = 0; 537 int timedout = 0; 538 again: 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; 536 552 } 537 553 … … 1236 1252 CHECK_GNUTLS_DO( ret = fd_tls_send_handle_error(conn, conn->cc_tls_para.session, buf + sent, len - sent), return ENOTCONN ); 1237 1253 } 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? */ 1239 1255 } 1240 1256 sent += ret; … … 1272 1288 } else { 1273 1289 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) ); 1275 1291 } else { 1276 1292 /* push the record to the appropriate session */ -
freeDiameter/cnxctx.h
r194 r201 103 103 int fd_sctp_get_remote_ep(int sock, struct fd_list * list); 104 104 int 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 );105 int fd_sctp_sendstr(int sock, uint16_t strid, uint8_t * buf, size_t len, int * cc_closing); 106 106 int fd_sctp_recvmeta(int sock, uint16_t * strid, uint8_t ** buf, size_t * len, int *event, int * cc_closing); 107 107 -
freeDiameter/sctp.c
r196 r201 1042 1042 1043 1043 /* Send a buffer over a specified stream */ 1044 int fd_sctp_sendstr(int sock, uint16_t strid, uint8_t * buf, size_t len )1044 int fd_sctp_sendstr(int sock, uint16_t strid, uint8_t * buf, size_t len, int * cc_closing) 1045 1045 { 1046 1046 struct msghdr mhdr; … … 1051 1051 } anci; 1052 1052 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); 1055 1057 1056 1058 memset(&mhdr, 0, sizeof(mhdr)); … … 1078 1080 1079 1081 TRACE_DEBUG(FULL, "Sending %db data on stream %hu of socket %d", len, strid, sock); 1080 1081 CHECK_SYS( ret = sendmsg(sock, &mhdr, 0) ); 1082 again: 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 ); 1082 1095 ASSERT( ret == len ); /* There should not be partial delivery with sendmsg... */ 1083 1096 -
freeDiameter/sctps.c
r194 r201 166 166 CHECK_PARAMS_DO( tr && data, { errno = EINVAL; return -1; } ); 167 167 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 ); 169 169 170 170 return len;
Note: See TracChangeset
for help on using the changeset viewer.