MCPcopy Create free account
hub / github.com/apache/trafficserver / connectUp

Method connectUp

src/iocore/net/UnixNetVConnection.cc:1151–1241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1149}
1150
1151int
1152UnixNetVConnection::connectUp(EThread *t, int fd)
1153{
1154 ink_assert(get_NetHandler(t)->mutex->thread_holding == this_ethread());
1155 int res;
1156 UnixSocket sock{fd};
1157
1158 thread = t;
1159 if (check_net_throttle(CONNECT)) {
1160 check_throttle_warning(CONNECT);
1161 res = -ENET_THROTTLING;
1162 Metrics::Counter::increment(net_rsb.connections_throttled_out);
1163 goto fail;
1164 }
1165
1166 // Force family to agree with remote (server) address.
1167 options.ip_family = con.addr.sa.sa_family;
1168
1169 //
1170 // Initialize this UnixNetVConnection
1171 //
1172 if (dbg_ctl_iocore_net.on()) {
1173 char addrbuf[INET6_ADDRSTRLEN];
1174 DbgPrint(dbg_ctl_iocore_net, "connectUp:: local_addr=%s:%d [%s]",
1175 options.local_ip.isValid() ? options.local_ip.toString(addrbuf, sizeof(addrbuf)) : "*", options.local_port,
1176 NetVCOptions::toString(options.addr_binding));
1177 }
1178
1179 // If this is getting called from the TS API, then we are wiring up a file descriptor
1180 // provided by the caller. In that case, we know that the socket is already connected.
1181 if (!sock.is_ok()) {
1182 // Due to multi-threads system, the fd returned from con.open() may exceed the limitation of check_net_throttle().
1183 res = con.open(options);
1184 if (res != 0) {
1185 goto fail;
1186 }
1187 } else {
1188 int len = sizeof(con.sock_type);
1189
1190 // This call will fail if fd is not a socket (e.g. it is a
1191 // eventfd or a regular file fd. That is ok, because sock_type
1192 // is only used when setting up the socket.
1193 safe_getsockopt(fd, SOL_SOCKET, SO_TYPE, reinterpret_cast<char *>(&con.sock_type), &len);
1194 sock.set_nonblocking();
1195 con.sock = sock;
1196 con.is_connected = true;
1197 con.is_bound = true;
1198 }
1199
1200 // Must connect after EventIO::Start() to avoid a race condition
1201 // when edge triggering is used.
1202 if ((res = get_NetHandler(t)->startIO(this)) < 0) {
1203 goto fail;
1204 }
1205
1206 if (!sock.is_ok()) {
1207 res = con.connect(nullptr, options);
1208 if (res != 0) {

Callers

nothing calls this directly

Calls 15

set_local_addrMethod · 0.95
free_threadMethod · 0.95
get_NetHandlerFunction · 0.85
this_ethreadFunction · 0.85
check_net_throttleFunction · 0.85
check_throttle_warningFunction · 0.85
incrementFunction · 0.85
safe_getsockoptFunction · 0.85
set_nonblockingMethod · 0.80
startIOMethod · 0.80
startCopMethod · 0.80
free_neteventMethod · 0.80

Tested by

no test coverage detected