Changeset 1186:56c36d1007b4 in freeDiameter for libfdcore/sctp3436.c
- Timestamp:
- Jun 7, 2013, 7:48:34 PM (11 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libfdcore/sctp3436.c
r1181 r1186 52 52 We also have a demux thread that reads the socket and store received data in the appropriate fifo 53 53 54 We have one gnutls_session per stream pair, and as many streams that read the gnutls records and save incoming data to the target queue.54 We have one gnutls_session per stream pair, and as many threads that read the gnutls records and save incoming data to the target queue. 55 55 56 56 This complexity is required because we cannot read a socket for a given stream only; we can only get the next message and find its stream. 57 57 */ 58 58 59 /* TODO: change this whole wrapper to DTLS which should not require many different threads*/59 /* Note that this mechanism is replaced by DTLS in RFC6733 */ 60 60 61 61 /*************************************************************/ … … 164 164 /*************************************************************/ 165 165 166 #ifdef GNUTLS_VERSION_300 167 /* Check if data is available for gnutls on a given context */ 168 static int sctp3436_pull_timeout(gnutls_transport_ptr_t tr, unsigned int ms) 169 { 170 struct sctp3436_ctx * ctx = (struct sctp3436_ctx *) tr; 171 struct timespec tsstore, *ts = NULL; 172 int ret; 173 174 TRACE_ENTRY("%p %d", tr, ms); 175 176 if (ctx->partial.buf) 177 return 1; /* data is already available for pull */ 178 179 if (ms) { 180 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &tsstore), return -1 ); 181 tsstore.tv_nsec += (long)ms * 1000000; 182 tsstore.tv_sec += tsstore.tv_nsec / 1000000000L; 183 tsstore.tv_nsec %= 1000000000L; 184 ts = &tsstore; 185 } 186 187 ret = fd_fifo_select ( ctx->raw_recv, ts ); 188 if (ret < 0) { 189 errno = -ret; 190 ret = -1; 191 } 192 193 return ret; 194 } 195 #endif /* GNUTLS_VERSION_300 */ 196 166 197 /* Send data over the connection, called by gnutls */ 198 #ifndef GNUTLS_VERSION_212 167 199 static ssize_t sctp3436_push(gnutls_transport_ptr_t tr, const void * data, size_t len) 168 200 { 169 201 struct sctp3436_ctx * ctx = (struct sctp3436_ctx *) tr; 202 struct iovec iov; 170 203 171 204 TRACE_ENTRY("%p %p %zd", tr, data, len); 172 205 CHECK_PARAMS_DO( tr && data, { errno = EINVAL; return -1; } ); 173 206 174 CHECK_FCT_DO( fd_sctp_sendstr(ctx->parent, ctx->strid, (uint8_t *)data, len), return -1 ); 175 176 return len; 177 } 207 iov.iov_base = (void *)data; 208 iov.iov_len = len; 209 210 return fd_sctp_sendstrv(ctx->parent, ctx->strid, &iov, 1); 211 } 212 #else /* GNUTLS_VERSION_212 */ 213 static ssize_t sctp3436_pushv(gnutls_transport_ptr_t tr, const giovec_t * iov, int iovcnt) 214 { 215 struct sctp3436_ctx * ctx = (struct sctp3436_ctx *) tr; 216 217 TRACE_ENTRY("%p %p %d", tr, iov, iovcnt); 218 CHECK_PARAMS_DO( tr && iov, { errno = EINVAL; return -1; } ); 219 220 return fd_sctp_sendstrv(ctx->parent, ctx->strid, (const struct iovec *)iov, iovcnt); 221 } 222 #endif /* GNUTLS_VERSION_212 */ 178 223 179 224 /* Retrieve data received on a stream and already demultiplexed */ … … 238 283 /* starting version 2.12, this call is not needed */ 239 284 GNUTLS_TRACE( gnutls_transport_set_lowat( session, 0 ) ); 285 #else /* GNUTLS_VERSION_300 */ 286 /* but in 3.0 we have to provide the pull_timeout callback */ 287 GNUTLS_TRACE( gnutls_transport_set_pull_timeout_function( session, sctp3436_pull_timeout ) ); 240 288 #endif /* GNUTLS_VERSION_300 */ 241 289 242 290 /* Set the push and pull callbacks */ 243 291 GNUTLS_TRACE( gnutls_transport_set_pull_function(session, sctp3436_pull) ); 292 #ifndef GNUTLS_VERSION_212 244 293 GNUTLS_TRACE( gnutls_transport_set_push_function(session, sctp3436_push) ); 294 #else /* GNUTLS_VERSION_212 */ 295 GNUTLS_TRACE( gnutls_transport_set_vec_push_function(session, sctp3436_pushv) ); 296 #endif /* GNUTLS_VERSION_212 */ 245 297 246 298 return;
Note: See TracChangeset
for help on using the changeset viewer.