}
// Latency measurement does not include time of sending commands to Fwmark
Stopwatch s;
- int ret = libcConnect(sockfd, addr, addrlen);
+ const int ret = libcConnect(sockfd, addr, addrlen);
// Save errno so it isn't clobbered by sending ON_CONNECT_COMPLETE
const int connectErrno = errno;
const unsigned latencyMs = lround(s.timeTaken());
// Send an ON_CONNECT_COMPLETE command that includes sockaddr and connect latency for reporting
if (shouldSetFwmark && FwmarkClient::shouldReportConnectComplete(addr->sa_family)) {
- FwmarkConnectInfo connectInfo(latencyMs, addr);
+ FwmarkConnectInfo connectInfo(ret == 0 ? 0 : connectErrno, latencyMs, addr);
// TODO: get the netId from the socket mark once we have continuous benchmark runs
FwmarkCommand command = {FwmarkCommand::ON_CONNECT_COMPLETE, /* netId (ignored) */ 0,
/* uid (filled in by the server) */ 0};
// Additional information sent with ON_CONNECT_COMPLETE command
struct FwmarkConnectInfo {
+ int error;
unsigned latencyMs;
union {
sockaddr s;
FwmarkConnectInfo() {}
- FwmarkConnectInfo(const unsigned latency, const sockaddr* saddr) {
+ FwmarkConnectInfo(const int connectErrno, const unsigned latency, const sockaddr* saddr) {
+ error = connectErrno;
latencyMs = latency;
if (saddr->sa_family == AF_INET) {
addr.sin = *((struct sockaddr_in*) saddr);
case FwmarkCommand::ON_CONNECT_COMPLETE: {
// Called after a socket connect() completes.
// This reports connect event including netId, destination IP address, destination port,
- // uid and connect latency
+ // uid, connect latency, and connect errno if any.
// Skip reporting if connect() happened on a UDP socket.
int socketProto;
addrstr, sizeof(addrstr), portstr, sizeof(portstr),
NI_NUMERICHOST | NI_NUMERICSERV);
- netdEventListener->onConnectEvent(fwmark.netId, connectInfo.latencyMs,
+ netdEventListener->onConnectEvent(fwmark.netId, connectInfo.error,
+ connectInfo.latencyMs,
(ret == 0) ? String16(addrstr) : String16(""),
(ret == 0) ? strtoul(portstr, NULL, 10) : 0, client->getUid());
}
/**
* Logs a single connect library call.
*
- * @param netId the ID of the network the lookup was performed on.
- * @param latencyMs the latency of the function call.
+ * @param netId the ID of the network the connect was performed on.
+ * @param error 0 if the connect call succeeded, otherwise errno if it failed.
+ * @param latencyMs the latency of the connect call.
* @param ipAddr destination IP address.
* @param port destination port number.
* @param uid the UID of the application that performed the connection.
*/
- void onConnectEvent(int netId, int latencyMs, String ipAddr, int port, int uid);
+ void onConnectEvent(int netId, int error, int latencyMs, String ipAddr, int port, int uid);
}