/* * peerProbeConnect will be called on dead peers by neighborUp */ static int peerProbeConnect(peer * p) { int fd; time_t ctimeout = p->connect_timeout > 0 ? p->connect_timeout : Config.Timeout.peer_connect; int ret = squid_curtime - p->stats.last_connect_failure > ctimeout * 10; if (p->test_fd != -1) return ret; /* probe already running */ if (squid_curtime - p->stats.last_connect_probe == 0) return ret; /* don't probe to often */ fd = comm_open(SOCK_STREAM, IPPROTO_TCP, getOutgoingAddr(NULL), 0, COMM_NONBLOCKING, p->name); if (fd < 0) return ret; commSetTimeout(fd, ctimeout, peerProbeConnectTimeout, p); p->test_fd = fd; p->stats.last_connect_probe = squid_curtime; commConnectStart(p->test_fd, p->host, p->http_port, peerProbeConnectDone, p, NULL); return ret; }
static void idnsRetryTcp(idns_query * q) { struct in_addr addr; int ns = (q->nsends - 1) % nns; idnsTcpCleanup(q); if (Config.Addrs.udp_outgoing.s_addr != no_addr.s_addr) addr = Config.Addrs.udp_outgoing; else addr = Config.Addrs.udp_incoming; q->tcp_socket = comm_open(SOCK_STREAM, IPPROTO_TCP, addr, 0, COMM_NONBLOCKING, "DNS TCP Socket"); q->queue_t = q->sent_t = current_time; dlinkAdd(q, &q->lru, &lru_list); commConnectStart(q->tcp_socket, inet_ntoa(nameservers[ns].S.sin_addr), ntohs(nameservers[ns].S.sin_port), idnsSendTcpQuery, q ); }
static void private_openAnIdleConn(char* server_ip,int server_port , struct in_addr outgoing , unsigned short tos, int ctimeout,FwdState *fwdState) { int fd = comm_openex(SOCK_STREAM,IPPROTO_TCP,outgoing,0,COMM_NONBLOCKING,tos,server_ip); if (fd < 0) { debug(151, 4) ("private_openAnIdleConn: %s\n", xstrerror()); return; } // debug(151,3)("mod_server_persist_connections-->private_openAnIdleConn: openIdleConn fd == %d,timeout:%d\n",fd,ctimeout); server *s = cbdataAlloc(server); s->ip_addr = xstrdup(server_ip); s->port = server_port; s->proto = fwdState->request->protocol; s->pconn_timeout=ctimeout; commSetTimeout(fd,ctimeout,fwdConnectIdleTimeout,s); /* if(ctimeout>36000) commSetTcpKeepalive(fd, 3600, ctimeout/36000, ctimeout); else commSetTcpKeepalive(fd, 3600, 100, 360000); */ commSetTcpKeepalive(fd, 1000, 10000, 360000); commConnectStart(fd, server_ip, server_port, private_openIdleConnDone, s); }
/* * start a TCP connection to the peer host on port 113 */ void identStart(struct sockaddr_in *me, struct sockaddr_in *my_peer, IDCB * callback, void *data) { IdentStateData *state; int fd; char key1[IDENT_KEY_SZ]; char key2[IDENT_KEY_SZ]; char key[IDENT_KEY_SZ]; snprintf(key1, IDENT_KEY_SZ, "%s:%d", inet_ntoa(me->sin_addr), ntohs(me->sin_port)); snprintf(key2, IDENT_KEY_SZ, "%s:%d", inet_ntoa(my_peer->sin_addr), ntohs(my_peer->sin_port)); snprintf(key, IDENT_KEY_SZ, "%s,%s", key1, key2); if ((state = hash_lookup(ident_hash, key)) != NULL) { identClientAdd(state, callback, data); return; } fd = comm_open(SOCK_STREAM, IPPROTO_TCP, me->sin_addr, 0, COMM_NONBLOCKING, "ident"); if (fd == COMM_ERROR) { /* Failed to get a local socket */ callback(NULL, data); return; } CBDATA_INIT_TYPE(IdentStateData); state = cbdataAlloc(IdentStateData); state->hash.key = xstrdup(key); state->fd = fd; state->me = *me; state->my_peer = *my_peer; identClientAdd(state, callback, data); hash_join(ident_hash, &state->hash); comm_add_close_handler(fd, identClose, state); commSetTimeout(fd, Config.Timeout.ident, identTimeout, state); commConnectStart(fd, inet_ntoa(state->my_peer.sin_addr), IDENT_PORT, identConnectDone, state); }
static void sslPeerSelectComplete(FwdServer * fs, void *data) { SslStateData *sslState = data; request_t *request = sslState->request; peer *g = NULL; if (fs == NULL) { ErrorState *err; err = errorCon(ERR_CANNOT_FORWARD, HTTP_SERVICE_UNAVAILABLE); err->request = requestLink(sslState->request); err->callback = sslErrorComplete; err->callback_data = sslState; errorSend(sslState->client.fd, err); return; } sslState->servers = fs; sslState->host = fs->peer ? fs->peer->host : request->host; if (fs->peer == NULL) { sslState->port = request->port; } else if (fs->peer->http_port != 0) { sslState->port = fs->peer->http_port; } else if ((g = peerFindByName(fs->peer->host))) { sslState->port = g->http_port; } else { sslState->port = CACHE_HTTP_PORT; } if (fs->peer) { sslState->request->peer_login = fs->peer->login; sslState->request->flags.proxying = 1; } else { sslState->request->flags.proxying = 0; } #if DELAY_POOLS /* no point using the delayIsNoDelay stuff since ssl is nice and simple */ if (g && g->options.no_delay && sslState->delay_id) { delayUnregisterDelayIdPtr(&sslState->delay_id); sslState->delay_id = 0; } #endif hierarchyNote(&sslState->request->hier, fs->peer ? fs->code : DIRECT, sslState->host); commConnectStart(sslState->server.fd, sslState->host, sslState->port, sslConnectDone, sslState); }