Lines Matching refs:ctx

962 static void cf_socket_ctx_init(struct cf_socket_ctx *ctx,  in cf_socket_ctx_init()  argument
966 memset(ctx, 0, sizeof(*ctx)); in cf_socket_ctx_init()
967 ctx->sock = CURL_SOCKET_BAD; in cf_socket_ctx_init()
968 ctx->transport = transport; in cf_socket_ctx_init()
969 Curl_sock_assign_addr(&ctx->addr, ai, transport); in cf_socket_ctx_init()
976 ctx->wblock_percent = (int)l; in cf_socket_ctx_init()
982 ctx->wpartial_percent = (int)l; in cf_socket_ctx_init()
988 ctx->rblock_percent = (int)l; in cf_socket_ctx_init()
994 ctx->recv_max = (size_t)l; in cf_socket_ctx_init()
1002 struct cf_socket_ctx *ctx = cf->ctx; in cf_socket_close() local
1004 if(ctx && CURL_SOCKET_BAD != ctx->sock) { in cf_socket_close()
1005 CURL_TRC_CF(data, cf, "cf_socket_close(%" FMT_SOCKET_T ")", ctx->sock); in cf_socket_close()
1006 if(ctx->sock == cf->conn->sock[cf->sockindex]) in cf_socket_close()
1008 socket_close(data, cf->conn, !ctx->accepted, ctx->sock); in cf_socket_close()
1009 ctx->sock = CURL_SOCKET_BAD; in cf_socket_close()
1010 if(ctx->active && cf->sockindex == FIRSTSOCKET) in cf_socket_close()
1012 ctx->active = FALSE; in cf_socket_close()
1013 memset(&ctx->started_at, 0, sizeof(ctx->started_at)); in cf_socket_close()
1014 memset(&ctx->connected_at, 0, sizeof(ctx->connected_at)); in cf_socket_close()
1025 struct cf_socket_ctx *ctx = cf->ctx; in cf_socket_shutdown() local
1027 CURL_TRC_CF(data, cf, "cf_socket_shutdown(%" FMT_SOCKET_T ")", ctx->sock); in cf_socket_shutdown()
1031 if(ctx->sock != CURL_SOCKET_BAD && in cf_socket_shutdown()
1032 ctx->transport == TRNSPRT_TCP && in cf_socket_shutdown()
1033 (curlx_nonblock(ctx->sock, TRUE) >= 0)) { in cf_socket_shutdown()
1035 (void)sread(ctx->sock, buf, sizeof(buf)); in cf_socket_shutdown()
1044 struct cf_socket_ctx *ctx = cf->ctx; in cf_socket_destroy() local
1048 free(ctx); in cf_socket_destroy()
1049 cf->ctx = NULL; in cf_socket_destroy()
1055 struct cf_socket_ctx *ctx = cf->ctx; in set_local_ip() local
1058 if((ctx->sock != CURL_SOCKET_BAD) && in set_local_ip()
1067 if(getsockname(ctx->sock, (struct sockaddr*) &ssloc, &slen)) { in set_local_ip()
1074 ctx->ip.local_ip, &ctx->ip.local_port)) { in set_local_ip()
1082 ctx->ip.local_ip[0] = 0; in set_local_ip()
1083 ctx->ip.local_port = -1; in set_local_ip()
1091 struct cf_socket_ctx *ctx = cf->ctx; in set_remote_ip() local
1094 if(!Curl_addr2string(&ctx->addr.curl_sa_addr, in set_remote_ip()
1095 (curl_socklen_t)ctx->addr.addrlen, in set_remote_ip()
1096 ctx->ip.remote_ip, &ctx->ip.remote_port)) { in set_remote_ip()
1099 ctx->error = errno; in set_remote_ip()
1111 struct cf_socket_ctx *ctx = cf->ctx; in cf_socket_open() local
1118 DEBUGASSERT(ctx->sock == CURL_SOCKET_BAD); in cf_socket_open()
1119 ctx->started_at = Curl_now(); in cf_socket_open()
1126 ctx->addr.socktype |= SOCK_NONBLOCK; in cf_socket_open()
1128 result = socket_open(data, &ctx->addr, &ctx->sock); in cf_socket_open()
1132 ctx->addr.socktype &= ~SOCK_NONBLOCK; in cf_socket_open()
1142 if(ctx->addr.family == AF_INET6) { in cf_socket_open()
1143 set_ipv6_v6only(ctx->sock, 0); in cf_socket_open()
1144 infof(data, " Trying [%s]:%d...", ctx->ip.remote_ip, ctx->ip.remote_port); in cf_socket_open()
1148 infof(data, " Trying %s:%d...", ctx->ip.remote_ip, ctx->ip.remote_port); in cf_socket_open()
1151 is_tcp = (ctx->addr.family == AF_INET in cf_socket_open()
1152 || ctx->addr.family == AF_INET6) && in cf_socket_open()
1153 ctx->addr.socktype == SOCK_STREAM; in cf_socket_open()
1155 is_tcp = (ctx->addr.family == AF_INET) && in cf_socket_open()
1156 ctx->addr.socktype == SOCK_STREAM; in cf_socket_open()
1159 tcpnodelay(data, ctx->sock); in cf_socket_open()
1161 nosigpipe(data, ctx->sock); in cf_socket_open()
1163 Curl_sndbuf_init(ctx->sock); in cf_socket_open()
1166 tcpkeepalive(data, ctx->sock); in cf_socket_open()
1172 ctx->sock, in cf_socket_open()
1186 if(ctx->addr.family == AF_INET in cf_socket_open()
1188 || ctx->addr.family == AF_INET6 in cf_socket_open()
1191 result = bindlocal(data, cf->conn, ctx->sock, ctx->addr.family, in cf_socket_open()
1192 Curl_ipv6_scope(&ctx->addr.curl_sa_addr)); in cf_socket_open()
1207 error = curlx_nonblock(ctx->sock, TRUE); in cf_socket_open()
1210 ctx->error = SOCKERRNO; in cf_socket_open()
1217 error = curlx_nonblock(ctx->sock, TRUE); in cf_socket_open()
1220 ctx->error = SOCKERRNO; in cf_socket_open()
1225 ctx->sock_connected = (ctx->addr.socktype != SOCK_DGRAM); in cf_socket_open()
1228 if(ctx->sock != CURL_SOCKET_BAD) { in cf_socket_open()
1229 socket_close(data, cf->conn, TRUE, ctx->sock); in cf_socket_open()
1230 ctx->sock = CURL_SOCKET_BAD; in cf_socket_open()
1235 ctx->connected_at = Curl_now(); in cf_socket_open()
1239 result, ctx->sock); in cf_socket_open()
1246 struct cf_socket_ctx *ctx = cf->ctx; in do_connect() local
1264 endpoints.sae_dstaddr = &ctx->addr.curl_sa_addr; in do_connect()
1265 endpoints.sae_dstaddrlen = ctx->addr.addrlen; in do_connect()
1267 rc = connectx(ctx->sock, &endpoints, SAE_ASSOCID_ANY, in do_connect()
1272 rc = connect(ctx->sock, &ctx->addr.curl_sa_addr, ctx->addr.addrlen); in do_connect()
1275 rc = connect(ctx->sock, &ctx->addr.curl_sa_addr, ctx->addr.addrlen); in do_connect()
1278 if(setsockopt(ctx->sock, IPPROTO_TCP, TCP_FASTOPEN_CONNECT, in do_connect()
1281 ctx->sock); in do_connect()
1283 rc = connect(ctx->sock, &ctx->addr.curl_sa_addr, ctx->addr.addrlen); in do_connect()
1286 rc = connect(ctx->sock, &ctx->addr.curl_sa_addr, ctx->addr.addrlen); in do_connect()
1292 rc = connect(ctx->sock, &ctx->addr.curl_sa_addr, in do_connect()
1293 (curl_socklen_t)ctx->addr.addrlen); in do_connect()
1302 struct cf_socket_ctx *ctx = cf->ctx; in cf_tcp_connect() local
1317 if(ctx->sock == CURL_SOCKET_BAD) { in cf_tcp_connect()
1334 ctx->ip.local_ip, ctx->ip.local_port); in cf_tcp_connect()
1336 result = socket_connect_result(data, ctx->ip.remote_ip, error); in cf_tcp_connect()
1346 (void)verifyconnect(ctx->sock, NULL); in cf_tcp_connect()
1349 rc = SOCKET_WRITABLE(ctx->sock, 0); in cf_tcp_connect()
1356 if(verifyconnect(ctx->sock, &ctx->error)) { in cf_tcp_connect()
1358 ctx->connected_at = Curl_now(); in cf_tcp_connect()
1367 (void)verifyconnect(ctx->sock, &ctx->error); in cf_tcp_connect()
1373 if(ctx->error) { in cf_tcp_connect()
1375 data->state.os_errno = ctx->error; in cf_tcp_connect()
1376 SET_SOCKERRNO(ctx->error); in cf_tcp_connect()
1381 ctx->ip.remote_ip, ctx->ip.remote_port, in cf_tcp_connect()
1382 ctx->ip.local_ip, ctx->ip.local_port, in cf_tcp_connect()
1383 Curl_strerror(ctx->error, buffer, sizeof(buffer))); in cf_tcp_connect()
1387 if(ctx->sock != CURL_SOCKET_BAD) { in cf_tcp_connect()
1388 socket_close(data, cf->conn, TRUE, ctx->sock); in cf_tcp_connect()
1389 ctx->sock = CURL_SOCKET_BAD; in cf_tcp_connect()
1402 struct cf_socket_ctx *ctx = cf->ctx; in cf_socket_get_host() local
1406 *pport = ctx->ip.remote_port; in cf_socket_get_host()
1413 struct cf_socket_ctx *ctx = cf->ctx; in cf_socket_adjust_pollset() local
1415 if(ctx->sock != CURL_SOCKET_BAD) { in cf_socket_adjust_pollset()
1420 if(ctx->listening) { in cf_socket_adjust_pollset()
1421 Curl_pollset_set_in_only(data, ps, ctx->sock); in cf_socket_adjust_pollset()
1423 FMT_SOCKET_T, ctx->sock); in cf_socket_adjust_pollset()
1426 Curl_pollset_set_out_only(data, ps, ctx->sock); in cf_socket_adjust_pollset()
1428 FMT_SOCKET_T, ctx->sock); in cf_socket_adjust_pollset()
1430 else if(!ctx->active) { in cf_socket_adjust_pollset()
1431 Curl_pollset_add_in(data, ps, ctx->sock); in cf_socket_adjust_pollset()
1433 FMT_SOCKET_T, ctx->sock); in cf_socket_adjust_pollset()
1441 struct cf_socket_ctx *ctx = cf->ctx; in cf_socket_data_pending() local
1445 readable = SOCKET_READABLE(ctx->sock, 0); in cf_socket_data_pending()
1455 static void win_update_sndbuf_size(struct cf_socket_ctx *ctx) in win_update_sndbuf_size() argument
1461 if(Curl_timediff(n, ctx->last_sndbuf_query_at) > 1000) { in win_update_sndbuf_size()
1462 if(!WSAIoctl(ctx->sock, SIO_IDEAL_SEND_BACKLOG_QUERY, 0, 0, in win_update_sndbuf_size()
1464 ideal != ctx->sndbuf_size && in win_update_sndbuf_size()
1465 !setsockopt(ctx->sock, SOL_SOCKET, SO_SNDBUF, in win_update_sndbuf_size()
1467 ctx->sndbuf_size = ideal; in win_update_sndbuf_size()
1469 ctx->last_sndbuf_query_at = n; in win_update_sndbuf_size()
1479 struct cf_socket_ctx *ctx = cf->ctx; in cf_socket_send() local
1487 cf->conn->sock[cf->sockindex] = ctx->sock; in cf_socket_send()
1491 if(ctx->wblock_percent > 0) { in cf_socket_send()
1494 if(c >= ((100-ctx->wblock_percent)*256/100)) { in cf_socket_send()
1502 if(cf->cft != &Curl_cft_udp && ctx->wpartial_percent > 0 && len > 8) { in cf_socket_send()
1503 len = len * ctx->wpartial_percent / 100; in cf_socket_send()
1513 nwritten = sendto(ctx->sock, buf, len, MSG_FASTOPEN, in cf_socket_send()
1520 nwritten = swrite(ctx->sock, buf, len); in cf_socket_send()
1551 win_update_sndbuf_size(ctx); in cf_socket_send()
1563 struct cf_socket_ctx *ctx = cf->ctx; in cf_socket_recv() local
1570 if(cf->cft != &Curl_cft_udp && ctx->rblock_percent > 0) { in cf_socket_recv()
1573 if(c >= ((100-ctx->rblock_percent)*256/100)) { in cf_socket_recv()
1579 if(cf->cft != &Curl_cft_udp && ctx->recv_max && ctx->recv_max < len) { in cf_socket_recv()
1581 len = ctx->recv_max; in cf_socket_recv()
1588 nread = sread(ctx->sock, buf, len); in cf_socket_recv()
1619 if(nread > 0 && !ctx->got_first_byte) { in cf_socket_recv()
1620 ctx->first_byte_at = Curl_now(); in cf_socket_recv()
1621 ctx->got_first_byte = TRUE; in cf_socket_recv()
1631 struct cf_socket_ctx *ctx = cf->ctx; in cf_socket_update_data() local
1632 data->info.primary = ctx->ip; in cf_socket_update_data()
1640 struct cf_socket_ctx *ctx = cf->ctx; in cf_socket_active() local
1643 cf->conn->sock[cf->sockindex] = ctx->sock; in cf_socket_active()
1646 cf->conn->primary = ctx->ip; in cf_socket_active()
1647 cf->conn->remote_addr = &ctx->addr; in cf_socket_active()
1649 cf->conn->bits.ipv6 = (ctx->addr.family == AF_INET6); in cf_socket_active()
1653 cf->conn->secondary = ctx->ip; in cf_socket_active()
1655 ctx->active = TRUE; in cf_socket_active()
1662 struct cf_socket_ctx *ctx = cf->ctx; in cf_socket_cntrl() local
1675 ctx->sock = CURL_SOCKET_BAD; in cf_socket_cntrl()
1685 struct cf_socket_ctx *ctx = cf->ctx; in cf_socket_conn_is_alive() local
1691 if(!ctx || ctx->sock == CURL_SOCKET_BAD) in cf_socket_conn_is_alive()
1695 pfd[0].fd = ctx->sock; in cf_socket_conn_is_alive()
1722 struct cf_socket_ctx *ctx = cf->ctx; in cf_socket_query() local
1727 *((curl_socket_t *)pres2) = ctx->sock; in cf_socket_query()
1730 if(ctx->got_first_byte) { in cf_socket_query()
1731 timediff_t ms = Curl_timediff(ctx->first_byte_at, ctx->started_at); in cf_socket_query()
1739 switch(ctx->transport) { in cf_socket_query()
1744 if(ctx->got_first_byte) { in cf_socket_query()
1745 *when = ctx->first_byte_at; in cf_socket_query()
1750 *when = ctx->connected_at; in cf_socket_query()
1757 *pres1 = (ctx->addr.family == AF_INET6); in cf_socket_query()
1761 *(struct ip_quadruple *)pres2 = ctx->ip; in cf_socket_query()
1796 struct cf_socket_ctx *ctx = NULL; in Curl_cf_tcp_create() local
1803 ctx = calloc(1, sizeof(*ctx)); in Curl_cf_tcp_create()
1804 if(!ctx) { in Curl_cf_tcp_create()
1808 cf_socket_ctx_init(ctx, ai, transport); in Curl_cf_tcp_create()
1810 result = Curl_cf_create(&cf, &Curl_cft_tcp, ctx); in Curl_cf_tcp_create()
1816 Curl_safefree(ctx); in Curl_cf_tcp_create()
1825 struct cf_socket_ctx *ctx = cf->ctx; in cf_udp_setup_quic() local
1832 DEBUGASSERT(ctx->sock != CURL_SOCKET_BAD); in cf_udp_setup_quic()
1834 rc = connect(ctx->sock, &ctx->addr.curl_sa_addr, in cf_udp_setup_quic()
1835 (curl_socklen_t)ctx->addr.addrlen); in cf_udp_setup_quic()
1837 return socket_connect_result(data, ctx->ip.remote_ip, SOCKERRNO); in cf_udp_setup_quic()
1839 ctx->sock_connected = TRUE; in cf_udp_setup_quic()
1843 (ctx->transport == TRNSPRT_QUIC) ? "QUIC" : "UDP", in cf_udp_setup_quic()
1844 ctx->sock, ctx->ip.local_ip, ctx->ip.local_port, in cf_udp_setup_quic()
1845 ctx->ip.remote_ip, ctx->ip.remote_port); in cf_udp_setup_quic()
1852 switch(ctx->addr.family) { in cf_udp_setup_quic()
1856 (void)setsockopt(ctx->sock, IPPROTO_IP, IP_MTU_DISCOVER, &val, in cf_udp_setup_quic()
1864 (void)setsockopt(ctx->sock, IPPROTO_IPV6, IPV6_MTU_DISCOVER, &val, in cf_udp_setup_quic()
1874 (void)setsockopt(ctx->sock, IPPROTO_UDP, UDP_GRO, &one, in cf_udp_setup_quic()
1885 struct cf_socket_ctx *ctx = cf->ctx; in cf_udp_connect() local
1894 if(ctx->sock == CURL_SOCKET_BAD) { in cf_udp_connect()
1901 if(ctx->transport == TRNSPRT_QUIC) { in cf_udp_connect()
1907 ctx->sock, ctx->ip.local_ip, ctx->ip.local_port); in cf_udp_connect()
1911 FMT_SOCKET_T " (unconnected)", ctx->sock); in cf_udp_connect()
1945 struct cf_socket_ctx *ctx = NULL; in Curl_cf_udp_create() local
1952 ctx = calloc(1, sizeof(*ctx)); in Curl_cf_udp_create()
1953 if(!ctx) { in Curl_cf_udp_create()
1957 cf_socket_ctx_init(ctx, ai, transport); in Curl_cf_udp_create()
1959 result = Curl_cf_create(&cf, &Curl_cft_udp, ctx); in Curl_cf_udp_create()
1965 Curl_safefree(ctx); in Curl_cf_udp_create()
1997 struct cf_socket_ctx *ctx = NULL; in Curl_cf_unix_create() local
2004 ctx = calloc(1, sizeof(*ctx)); in Curl_cf_unix_create()
2005 if(!ctx) { in Curl_cf_unix_create()
2009 cf_socket_ctx_init(ctx, ai, transport); in Curl_cf_unix_create()
2011 result = Curl_cf_create(&cf, &Curl_cft_unix, ctx); in Curl_cf_unix_create()
2017 Curl_safefree(ctx); in Curl_cf_unix_create()
2026 struct cf_socket_ctx *ctx = cf->ctx; in cf_tcp_accept_timeleft() local
2045 timeout_ms -= Curl_timediff(now, ctx->started_at); in cf_tcp_accept_timeleft()
2056 struct cf_socket_ctx *ctx = cf->ctx; in cf_tcp_set_accepted_remote_ip() local
2062 ctx->ip.remote_ip[0] = 0; in cf_tcp_set_accepted_remote_ip()
2063 ctx->ip.remote_port = 0; in cf_tcp_set_accepted_remote_ip()
2066 if(getpeername(ctx->sock, (struct sockaddr*) &ssrem, &plen)) { in cf_tcp_set_accepted_remote_ip()
2073 ctx->ip.remote_ip, &ctx->ip.remote_port)) { in cf_tcp_set_accepted_remote_ip()
2079 ctx->ip.remote_ip[0] = 0; in cf_tcp_set_accepted_remote_ip()
2080 ctx->ip.remote_port = 0; in cf_tcp_set_accepted_remote_ip()
2089 struct cf_socket_ctx *ctx = cf->ctx; in cf_tcp_accept_connect() local
2117 " ip=%s:%d", ctx->sock, ctx->ip.local_ip, ctx->ip.local_port); in cf_tcp_accept_connect()
2118 socketstate = Curl_socket_check(ctx->sock, CURL_SOCKET_BAD, in cf_tcp_accept_connect()
2140 if(0 == getsockname(ctx->sock, (struct sockaddr *) &add, &size)) { in cf_tcp_accept_connect()
2142 s_accepted = accept(ctx->sock, (struct sockaddr *) &add, &size); in cf_tcp_accept_connect()
2153 ctx->listening = FALSE; in cf_tcp_accept_connect()
2154 ctx->accepted = TRUE; in cf_tcp_accept_connect()
2155 socket_close(data, cf->conn, TRUE, ctx->sock); in cf_tcp_accept_connect()
2156 ctx->sock = s_accepted; in cf_tcp_accept_connect()
2158 cf->conn->sock[cf->sockindex] = ctx->sock; in cf_tcp_accept_connect()
2161 ctx->active = TRUE; in cf_tcp_accept_connect()
2162 ctx->connected_at = Curl_now(); in cf_tcp_accept_connect()
2166 ctx->sock, ctx->ip.remote_ip, ctx->ip.remote_port); in cf_tcp_accept_connect()
2174 ctx->sock, CURLSOCKTYPE_ACCEPT); in cf_tcp_accept_connect()
2208 struct cf_socket_ctx *ctx = NULL; in Curl_conn_tcp_listen_set() local
2214 ctx = calloc(1, sizeof(*ctx)); in Curl_conn_tcp_listen_set()
2215 if(!ctx) { in Curl_conn_tcp_listen_set()
2219 ctx->transport = conn->transport; in Curl_conn_tcp_listen_set()
2220 ctx->sock = *s; in Curl_conn_tcp_listen_set()
2221 ctx->listening = TRUE; in Curl_conn_tcp_listen_set()
2222 ctx->accepted = FALSE; in Curl_conn_tcp_listen_set()
2223 result = Curl_cf_create(&cf, &Curl_cft_tcp_accept, ctx); in Curl_conn_tcp_listen_set()
2228 ctx->started_at = Curl_now(); in Curl_conn_tcp_listen_set()
2229 conn->sock[sockindex] = ctx->sock; in Curl_conn_tcp_listen_set()
2232 " ip=%s:%d", ctx->sock, in Curl_conn_tcp_listen_set()
2233 ctx->ip.local_ip, ctx->ip.local_port); in Curl_conn_tcp_listen_set()
2238 Curl_safefree(ctx); in Curl_conn_tcp_listen_set()
2273 if(cf_is_socket(cf) && cf->ctx) { in Curl_cf_socket_peek()
2274 struct cf_socket_ctx *ctx = cf->ctx; in Curl_cf_socket_peek() local
2277 *psock = ctx->sock; in Curl_cf_socket_peek()
2279 *paddr = &ctx->addr; in Curl_cf_socket_peek()
2281 *pip = ctx->ip; in Curl_cf_socket_peek()