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

Function client_handler

src/api/InkAPITest.cc:1450–1514  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1448}
1449
1450int
1451client_handler(TSCont contp, TSEvent event, void *data)
1452{
1453 SDK_NetVConn_Params *params = static_cast<SDK_NetVConn_Params *>(TSContDataGet(contp));
1454
1455 if (event == TS_EVENT_NET_CONNECT_FAILED) {
1456 SDK_RPRINT(params->test, params->api, "ClientConnect", TC_FAIL, "can't connect to server");
1457
1458 *params->pstatus = REGRESSION_TEST_FAILED;
1459
1460 // no need to continue, return
1461 // Fix me: how to deal with server side cont?
1462 TSContDestroy(contp);
1463 return 1;
1464 } else if (TS_EVENT_NET_CONNECT == event) {
1465 sockaddr const *addr = TSNetVConnRemoteAddrGet(static_cast<TSVConn>(data));
1466 uint16_t input_server_port = ats_ip_port_host_order(addr);
1467
1468 // If DEFER_ACCEPT is enabled in the OS then the user space accept() doesn't
1469 // happen until data arrives on the socket. Because we're just testing the accept()
1470 // we write a small amount of ignored data to make sure this gets triggered.
1471 UnixNetVConnection *vc = static_cast<UnixNetVConnection *>(data);
1472 ink_release_assert(vc->con.sock.write("Bob's your uncle", 16) != 0);
1473
1474 sleep(1); // XXX this sleep ensures the server end gets the accept event.
1475
1476 if (ats_is_ip_loopback(addr)) {
1477 SDK_RPRINT(params->test, params->api, "TSNetVConnRemoteIPGet", TC_PASS, "ok");
1478 } else {
1479 ip_text_buffer s, ipb;
1480 IpEndpoint loopback;
1481 ats_ip4_set(&loopback, htonl(INADDR_LOOPBACK));
1482 SDK_RPRINT(params->test, params->api, "TSNetVConnRemoteIPGet", TC_FAIL, "server ip [%s] is incorrect - expected [%s]",
1483 ats_ip_ntop(addr, s, sizeof s), ats_ip_ntop(&loopback.sa, ipb, sizeof ipb));
1484
1485 TSContDestroy(contp);
1486 // Fix me: how to deal with server side cont?
1487 *params->pstatus = REGRESSION_TEST_FAILED;
1488 return 1;
1489 }
1490
1491 if (input_server_port == params->port) {
1492 SDK_RPRINT(params->test, params->api, "TSNetVConnRemotePortGet", TC_PASS, "ok");
1493 } else {
1494 SDK_RPRINT(params->test, params->api, "TSNetVConnRemotePortGet", TC_FAIL, "server port [%d] is incorrect -- expected [%d]",
1495 input_server_port, params->port);
1496
1497 TSContDestroy(contp);
1498 // Fix me: how to deal with server side cont?
1499 *params->pstatus = REGRESSION_TEST_FAILED;
1500 return 1;
1501 }
1502
1503 SDK_RPRINT(params->test, params->api, "TSNetConnect", TC_PASS, "ok");
1504
1505 // XXX We really ought to do a write/read exchange with the server. The sleep above works around this.
1506
1507 // Looks good from the client end. Next we disconnect so that the server end can set the final test status.

Callers

nothing calls this directly

Calls 10

TSContDataGetFunction · 0.85
SDK_RPRINTFunction · 0.85
TSContDestroyFunction · 0.85
TSNetVConnRemoteAddrGetFunction · 0.85
ats_ip_port_host_orderFunction · 0.85
ats_is_ip_loopbackFunction · 0.85
ats_ip4_setFunction · 0.85
TSVConnCloseFunction · 0.85
ats_ip_ntopFunction · 0.50
writeMethod · 0.45

Tested by

no test coverage detected