Mercurial > hg > freeDiameter
comparison freeDiameter/sctp.c @ 209:b9f48f2f2a22
Some cleanups in the code
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Tue, 16 Feb 2010 15:29:55 +0900 |
parents | 1b47afa59358 |
children | 5f2ce627db3c |
comparison
equal
deleted
inserted
replaced
208:e1da03ba112f | 209:b9f48f2f2a22 |
---|---|
1039 /* Done! */ | 1039 /* Done! */ |
1040 return 0; | 1040 return 0; |
1041 } | 1041 } |
1042 | 1042 |
1043 /* Send a buffer over a specified stream */ | 1043 /* Send a buffer over a specified stream */ |
1044 int fd_sctp_sendstr(int sock, uint16_t strid, uint8_t * buf, size_t len, int * cc_closing) | 1044 int fd_sctp_sendstr(int sock, uint16_t strid, uint8_t * buf, size_t len, int * cc_status) |
1045 { | 1045 { |
1046 struct msghdr mhdr; | 1046 struct msghdr mhdr; |
1047 struct iovec iov; | 1047 struct iovec iov; |
1048 struct { | 1048 struct { |
1049 struct cmsghdr hdr; | 1049 struct cmsghdr hdr; |
1050 struct sctp_sndrcvinfo sndrcv; | 1050 struct sctp_sndrcvinfo sndrcv; |
1051 } anci; | 1051 } anci; |
1052 ssize_t ret; | 1052 ssize_t ret; |
1053 int timedout = 0; | 1053 int timedout = 0; |
1054 | 1054 |
1055 TRACE_ENTRY("%d %hu %p %zd %p", sock, strid, buf, len, cc_closing); | 1055 TRACE_ENTRY("%d %hu %p %zd %p", sock, strid, buf, len, cc_status); |
1056 CHECK_PARAMS(cc_closing); | 1056 CHECK_PARAMS(cc_status); |
1057 | 1057 |
1058 memset(&mhdr, 0, sizeof(mhdr)); | 1058 memset(&mhdr, 0, sizeof(mhdr)); |
1059 memset(&iov, 0, sizeof(iov)); | 1059 memset(&iov, 0, sizeof(iov)); |
1060 memset(&anci, 0, sizeof(anci)); | 1060 memset(&anci, 0, sizeof(anci)); |
1061 | 1061 |
1081 TRACE_DEBUG(FULL, "Sending %db data on stream %hu of socket %d", len, strid, sock); | 1081 TRACE_DEBUG(FULL, "Sending %db data on stream %hu of socket %d", len, strid, sock); |
1082 again: | 1082 again: |
1083 ret = sendmsg(sock, &mhdr, 0); | 1083 ret = sendmsg(sock, &mhdr, 0); |
1084 /* Handle special case of timeout */ | 1084 /* Handle special case of timeout */ |
1085 if ((ret < 0) && (errno == EAGAIN)) { | 1085 if ((ret < 0) && (errno == EAGAIN)) { |
1086 if (!*cc_closing) | 1086 if (!(*cc_status & CC_STATUS_CLOSING)) |
1087 goto again; /* don't care, just ignore */ | 1087 goto again; /* don't care, just ignore */ |
1088 if (!timedout) { | 1088 if (!timedout) { |
1089 timedout ++; /* allow for one timeout while closing */ | 1089 timedout ++; /* allow for one timeout while closing */ |
1090 goto again; | 1090 goto again; |
1091 } | 1091 } |
1096 | 1096 |
1097 return 0; | 1097 return 0; |
1098 } | 1098 } |
1099 | 1099 |
1100 /* Receive the next data from the socket, or next notification */ | 1100 /* Receive the next data from the socket, or next notification */ |
1101 int fd_sctp_recvmeta(int sock, uint16_t * strid, uint8_t ** buf, size_t * len, int *event, int * cc_closing) | 1101 int fd_sctp_recvmeta(int sock, uint16_t * strid, uint8_t ** buf, size_t * len, int *event, int * cc_status) |
1102 { | 1102 { |
1103 ssize_t ret = 0; | 1103 ssize_t ret = 0; |
1104 struct msghdr mhdr; | 1104 struct msghdr mhdr; |
1105 char ancidata[ CMSG_BUF_LEN ]; | 1105 char ancidata[ CMSG_BUF_LEN ]; |
1106 struct iovec iov; | 1106 struct iovec iov; |
1107 uint8_t *data = NULL; | 1107 uint8_t *data = NULL; |
1108 size_t bufsz = 0, datasize = 0; | 1108 size_t bufsz = 0, datasize = 0; |
1109 size_t mempagesz = sysconf(_SC_PAGESIZE); /* We alloc buffer by memory pages for efficiency */ | 1109 size_t mempagesz = sysconf(_SC_PAGESIZE); /* We alloc buffer by memory pages for efficiency */ |
1110 int timedout = 0; | 1110 int timedout = 0; |
1111 | 1111 |
1112 TRACE_ENTRY("%d %p %p %p %p %p", sock, strid, buf, len, event, cc_closing); | 1112 TRACE_ENTRY("%d %p %p %p %p %p", sock, strid, buf, len, event, cc_status); |
1113 CHECK_PARAMS( (sock > 0) && buf && len && event && cc_closing ); | 1113 CHECK_PARAMS( (sock > 0) && buf && len && event && cc_status ); |
1114 | 1114 |
1115 /* Cleanup out parameters */ | 1115 /* Cleanup out parameters */ |
1116 *buf = NULL; | 1116 *buf = NULL; |
1117 *len = 0; | 1117 *len = 0; |
1118 *event = 0; | 1118 *event = 0; |
1142 ret = recvmsg(sock, &mhdr, 0); | 1142 ret = recvmsg(sock, &mhdr, 0); |
1143 pthread_cleanup_pop(0); | 1143 pthread_cleanup_pop(0); |
1144 | 1144 |
1145 /* First, handle timeouts (same as fd_cnx_s_recv) */ | 1145 /* First, handle timeouts (same as fd_cnx_s_recv) */ |
1146 if ((ret < 0) && (errno == EAGAIN)) { | 1146 if ((ret < 0) && (errno == EAGAIN)) { |
1147 if (!*cc_closing) | 1147 if (!(*cc_status & CC_STATUS_CLOSING)) |
1148 goto again; /* don't care, just ignore */ | 1148 goto again; /* don't care, just ignore */ |
1149 if (!timedout) { | 1149 if (!timedout) { |
1150 timedout ++; /* allow for one timeout while closing */ | 1150 timedout ++; /* allow for one timeout while closing */ |
1151 goto again; | 1151 goto again; |
1152 } | 1152 } |