Lines Matching refs:tctx

193 	struct tcp_ctx *tctx;  in tcp_setup_new()  local
201 tctx = malloc(sizeof(*tctx)); in tcp_setup_new()
202 if (tctx == NULL) in tcp_setup_new()
206 if ((ret = tcp_addr(addr, PROTO_TCP_DEFAULT_PORT, &tctx->tc_sa)) != 0) { in tcp_setup_new()
207 free(tctx); in tcp_setup_new()
211 PJDLOG_ASSERT(tctx->tc_sa.ss_family != AF_UNSPEC); in tcp_setup_new()
213 tctx->tc_fd = socket(tctx->tc_sa.ss_family, SOCK_STREAM, 0); in tcp_setup_new()
214 if (tctx->tc_fd == -1) { in tcp_setup_new()
216 free(tctx); in tcp_setup_new()
220 PJDLOG_ASSERT(tctx->tc_sa.ss_family != AF_UNSPEC); in tcp_setup_new()
224 if (setsockopt(tctx->tc_fd, IPPROTO_TCP, TCP_NODELAY, &nodelay, in tcp_setup_new()
229 tctx->tc_side = side; in tcp_setup_new()
230 tctx->tc_magic = TCP_CTX_MAGIC; in tcp_setup_new()
231 *ctxp = tctx; in tcp_setup_new()
239 struct tcp_ctx *tctx; in tcp_setup_wrap() local
246 tctx = malloc(sizeof(*tctx)); in tcp_setup_wrap()
247 if (tctx == NULL) in tcp_setup_wrap()
250 tctx->tc_fd = fd; in tcp_setup_wrap()
251 tctx->tc_sa.ss_family = AF_UNSPEC; in tcp_setup_wrap()
252 tctx->tc_side = side; in tcp_setup_wrap()
253 tctx->tc_magic = TCP_CTX_MAGIC; in tcp_setup_wrap()
254 *ctxp = tctx; in tcp_setup_wrap()
262 struct tcp_ctx *tctx; in tcp_client() local
269 tctx = *ctxp; in tcp_client()
274 tcp_close(tctx); in tcp_client()
277 if (bind(tctx->tc_fd, (struct sockaddr *)&sa, sa.ss_len) == -1) { in tcp_client()
279 tcp_close(tctx); in tcp_client()
288 struct tcp_ctx *tctx = ctx; in tcp_connect() local
291 PJDLOG_ASSERT(tctx != NULL); in tcp_connect()
292 PJDLOG_ASSERT(tctx->tc_magic == TCP_CTX_MAGIC); in tcp_connect()
293 PJDLOG_ASSERT(tctx->tc_side == TCP_SIDE_CLIENT); in tcp_connect()
294 PJDLOG_ASSERT(tctx->tc_fd >= 0); in tcp_connect()
295 PJDLOG_ASSERT(tctx->tc_sa.ss_family != AF_UNSPEC); in tcp_connect()
298 flags = fcntl(tctx->tc_fd, F_GETFL); in tcp_connect()
308 if (fcntl(tctx->tc_fd, F_SETFL, flags) == -1) { in tcp_connect()
314 if (connect(tctx->tc_fd, (struct sockaddr *)&tctx->tc_sa, in tcp_connect()
315 tctx->tc_sa.ss_len) == 0) { in tcp_connect()
331 if (fcntl(tctx->tc_fd, F_SETFL, flags) == -1) { in tcp_connect()
343 struct tcp_ctx *tctx = ctx; in tcp_connect_wait() local
349 PJDLOG_ASSERT(tctx != NULL); in tcp_connect_wait()
350 PJDLOG_ASSERT(tctx->tc_magic == TCP_CTX_MAGIC); in tcp_connect_wait()
351 PJDLOG_ASSERT(tctx->tc_side == TCP_SIDE_CLIENT); in tcp_connect_wait()
352 PJDLOG_ASSERT(tctx->tc_fd >= 0); in tcp_connect_wait()
359 FD_SET(tctx->tc_fd, &fdset); in tcp_connect_wait()
360 ret = select(tctx->tc_fd + 1, NULL, &fdset, NULL, &tv); in tcp_connect_wait()
372 PJDLOG_ASSERT(FD_ISSET(tctx->tc_fd, &fdset)); in tcp_connect_wait()
374 if (getsockopt(tctx->tc_fd, SOL_SOCKET, SO_ERROR, &error, in tcp_connect_wait()
388 flags = fcntl(tctx->tc_fd, F_GETFL); in tcp_connect_wait()
396 if (fcntl(tctx->tc_fd, F_SETFL, flags) == -1) { in tcp_connect_wait()
408 struct tcp_ctx *tctx; in tcp_server() local
415 tctx = *ctxp; in tcp_server()
419 (void)setsockopt(tctx->tc_fd, SOL_SOCKET, SO_REUSEADDR, &val, in tcp_server()
422 PJDLOG_ASSERT(tctx->tc_sa.ss_family != AF_UNSPEC); in tcp_server()
424 if (bind(tctx->tc_fd, (struct sockaddr *)&tctx->tc_sa, in tcp_server()
425 tctx->tc_sa.ss_len) == -1) { in tcp_server()
427 tcp_close(tctx); in tcp_server()
430 if (listen(tctx->tc_fd, 8) == -1) { in tcp_server()
432 tcp_close(tctx); in tcp_server()
442 struct tcp_ctx *tctx = ctx; in tcp_accept() local
447 PJDLOG_ASSERT(tctx != NULL); in tcp_accept()
448 PJDLOG_ASSERT(tctx->tc_magic == TCP_CTX_MAGIC); in tcp_accept()
449 PJDLOG_ASSERT(tctx->tc_side == TCP_SIDE_SERVER_LISTEN); in tcp_accept()
450 PJDLOG_ASSERT(tctx->tc_fd >= 0); in tcp_accept()
451 PJDLOG_ASSERT(tctx->tc_sa.ss_family != AF_UNSPEC); in tcp_accept()
457 fromlen = tctx->tc_sa.ss_len; in tcp_accept()
458 newtctx->tc_fd = accept(tctx->tc_fd, (struct sockaddr *)&tctx->tc_sa, in tcp_accept()
484 struct tcp_ctx *tctx = ctx; in tcp_send() local
486 PJDLOG_ASSERT(tctx != NULL); in tcp_send()
487 PJDLOG_ASSERT(tctx->tc_magic == TCP_CTX_MAGIC); in tcp_send()
488 PJDLOG_ASSERT(tctx->tc_fd >= 0); in tcp_send()
491 return (proto_common_send(tctx->tc_fd, data, size, -1)); in tcp_send()
497 struct tcp_ctx *tctx = ctx; in tcp_recv() local
499 PJDLOG_ASSERT(tctx != NULL); in tcp_recv()
500 PJDLOG_ASSERT(tctx->tc_magic == TCP_CTX_MAGIC); in tcp_recv()
501 PJDLOG_ASSERT(tctx->tc_fd >= 0); in tcp_recv()
504 return (proto_common_recv(tctx->tc_fd, data, size, NULL)); in tcp_recv()
510 const struct tcp_ctx *tctx = ctx; in tcp_descriptor() local
512 PJDLOG_ASSERT(tctx != NULL); in tcp_descriptor()
513 PJDLOG_ASSERT(tctx->tc_magic == TCP_CTX_MAGIC); in tcp_descriptor()
515 return (tctx->tc_fd); in tcp_descriptor()
521 const struct tcp_ctx *tctx = ctx; in tcp_address_match() local
525 PJDLOG_ASSERT(tctx != NULL); in tcp_address_match()
526 PJDLOG_ASSERT(tctx->tc_magic == TCP_CTX_MAGIC); in tcp_address_match()
532 if (getpeername(tctx->tc_fd, (struct sockaddr *)&sa2, &salen) == -1) in tcp_address_match()
567 const struct tcp_ctx *tctx = ctx; in tcp_local_address() local
571 PJDLOG_ASSERT(tctx != NULL); in tcp_local_address()
572 PJDLOG_ASSERT(tctx->tc_magic == TCP_CTX_MAGIC); in tcp_local_address()
575 if (getsockname(tctx->tc_fd, (struct sockaddr *)&sa, &salen) == -1) { in tcp_local_address()
585 const struct tcp_ctx *tctx = ctx; in tcp_remote_address() local
589 PJDLOG_ASSERT(tctx != NULL); in tcp_remote_address()
590 PJDLOG_ASSERT(tctx->tc_magic == TCP_CTX_MAGIC); in tcp_remote_address()
593 if (getpeername(tctx->tc_fd, (struct sockaddr *)&sa, &salen) == -1) { in tcp_remote_address()
603 struct tcp_ctx *tctx = ctx; in tcp_close() local
605 PJDLOG_ASSERT(tctx != NULL); in tcp_close()
606 PJDLOG_ASSERT(tctx->tc_magic == TCP_CTX_MAGIC); in tcp_close()
608 if (tctx->tc_fd >= 0) in tcp_close()
609 close(tctx->tc_fd); in tcp_close()
610 tctx->tc_magic = 0; in tcp_close()
611 free(tctx); in tcp_close()