リビジョン | 483afa496bd0fc58aba0c56f1da8f059bd0fa85d (tree) |
---|---|
日時 | 2016-12-15 20:50:42 |
作者 | Hugo Benichi <hugobenichi@goog...> |
コミッター | Hugo Benichi |
DO NOT MERGE Add success/errno to connect() event reporting
Test: $ runtest -x system/netd/tests/netd_integration_test.cpp
Bug: 32198976
(cherry picked from commit 794c5c714a4d4cf169769ec956845a6fb24e7ebc)
Change-Id: I0a7990d7211d5355a48d941ee9659c16e38817ca
@@ -87,13 +87,13 @@ int netdClientConnect(int sockfd, const sockaddr* addr, socklen_t addrlen) { | ||
87 | 87 | } |
88 | 88 | // Latency measurement does not include time of sending commands to Fwmark |
89 | 89 | Stopwatch s; |
90 | - int ret = libcConnect(sockfd, addr, addrlen); | |
90 | + const int ret = libcConnect(sockfd, addr, addrlen); | |
91 | 91 | // Save errno so it isn't clobbered by sending ON_CONNECT_COMPLETE |
92 | 92 | const int connectErrno = errno; |
93 | 93 | const unsigned latencyMs = lround(s.timeTaken()); |
94 | 94 | // Send an ON_CONNECT_COMPLETE command that includes sockaddr and connect latency for reporting |
95 | 95 | if (shouldSetFwmark && FwmarkClient::shouldReportConnectComplete(addr->sa_family)) { |
96 | - FwmarkConnectInfo connectInfo(latencyMs, addr); | |
96 | + FwmarkConnectInfo connectInfo(ret == 0 ? 0 : connectErrno, latencyMs, addr); | |
97 | 97 | // TODO: get the netId from the socket mark once we have continuous benchmark runs |
98 | 98 | FwmarkCommand command = {FwmarkCommand::ON_CONNECT_COMPLETE, /* netId (ignored) */ 0, |
99 | 99 | /* uid (filled in by the server) */ 0}; |
@@ -23,6 +23,7 @@ | ||
23 | 23 | |
24 | 24 | // Additional information sent with ON_CONNECT_COMPLETE command |
25 | 25 | struct FwmarkConnectInfo { |
26 | + int error; | |
26 | 27 | unsigned latencyMs; |
27 | 28 | union { |
28 | 29 | sockaddr s; |
@@ -32,7 +33,8 @@ struct FwmarkConnectInfo { | ||
32 | 33 | |
33 | 34 | FwmarkConnectInfo() {} |
34 | 35 | |
35 | - FwmarkConnectInfo(const unsigned latency, const sockaddr* saddr) { | |
36 | + FwmarkConnectInfo(const int connectErrno, const unsigned latency, const sockaddr* saddr) { | |
37 | + error = connectErrno; | |
36 | 38 | latencyMs = latency; |
37 | 39 | if (saddr->sa_family == AF_INET) { |
38 | 40 | addr.sin = *((struct sockaddr_in*) saddr); |
@@ -165,7 +165,7 @@ int FwmarkServer::processClient(SocketClient* client, int* socketFd) { | ||
165 | 165 | case FwmarkCommand::ON_CONNECT_COMPLETE: { |
166 | 166 | // Called after a socket connect() completes. |
167 | 167 | // This reports connect event including netId, destination IP address, destination port, |
168 | - // uid and connect latency | |
168 | + // uid, connect latency, and connect errno if any. | |
169 | 169 | |
170 | 170 | // Skip reporting if connect() happened on a UDP socket. |
171 | 171 | int socketProto; |
@@ -185,7 +185,8 @@ int FwmarkServer::processClient(SocketClient* client, int* socketFd) { | ||
185 | 185 | addrstr, sizeof(addrstr), portstr, sizeof(portstr), |
186 | 186 | NI_NUMERICHOST | NI_NUMERICSERV); |
187 | 187 | |
188 | - netdEventListener->onConnectEvent(fwmark.netId, connectInfo.latencyMs, | |
188 | + netdEventListener->onConnectEvent(fwmark.netId, connectInfo.error, | |
189 | + connectInfo.latencyMs, | |
189 | 190 | (ret == 0) ? String16(addrstr) : String16(""), |
190 | 191 | (ret == 0) ? strtoul(portstr, NULL, 10) : 0, client->getUid()); |
191 | 192 | } |
@@ -52,11 +52,12 @@ oneway interface INetdEventListener { | ||
52 | 52 | /** |
53 | 53 | * Logs a single connect library call. |
54 | 54 | * |
55 | - * @param netId the ID of the network the lookup was performed on. | |
56 | - * @param latencyMs the latency of the function call. | |
55 | + * @param netId the ID of the network the connect was performed on. | |
56 | + * @param error 0 if the connect call succeeded, otherwise errno if it failed. | |
57 | + * @param latencyMs the latency of the connect call. | |
57 | 58 | * @param ipAddr destination IP address. |
58 | 59 | * @param port destination port number. |
59 | 60 | * @param uid the UID of the application that performed the connection. |
60 | 61 | */ |
61 | - void onConnectEvent(int netId, int latencyMs, String ipAddr, int port, int uid); | |
62 | + void onConnectEvent(int netId, int error, int latencyMs, String ipAddr, int port, int uid); | |
62 | 63 | } |