ext/common/ServerKit/Server.h in passenger-5.0.4 vs ext/common/ServerKit/Server.h in passenger-5.0.5
- old
+ new
@@ -1,8 +1,8 @@
/*
* Phusion Passenger - https://www.phusionpassenger.com/
- * Copyright (c) 2014 Phusion
+ * Copyright (c) 2014-2015 Phusion
*
* "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -260,19 +260,21 @@
error = true;
errcode = errno;
break;
}
- FdGuard guard(fd);
+ FdGuard guard(fd, NULL, 0);
client = checkoutClientObject();
TAILQ_INSERT_HEAD(&activeClients, client, nextClient.activeOrDisconnectedClient);
acceptedClients[acceptCount] = client;
activeClientCount++;
acceptCount++;
totalClientsAccepted++;
client->number = getNextClientNumber();
reinitializeClient(client, fd);
+ P_LOG_FILE_DESCRIPTOR_PURPOSE(fd, "Server " << getServerName()
+ << ", client " << getClientName(client));
guard.clear();
}
if (acceptCount > 0) {
SKS_DEBUG(acceptCount << " new client(s) accepted; there are now " <<
@@ -325,11 +327,11 @@
}
} else {
int fd = syscalls::accept(serverFd,
(struct sockaddr *) &u,
&addrlen);
- FdGuard guard(fd);
+ FdGuard guard(fd, __FILE__, __LINE__);
if (fd == -1) {
return -1;
} else {
try {
setNonBlocking(fd);
@@ -780,10 +782,12 @@
client = checkoutClientObject();
TAILQ_INSERT_HEAD(&activeClients, client, nextClient.activeOrDisconnectedClient);
acceptedClients[i] = client;
client->number = getNextClientNumber();
reinitializeClient(client, fds[i]);
+ P_LOG_FILE_DESCRIPTOR_PURPOSE(fds[i], "Server " << getServerName()
+ << ", client " << getClientName(client));
}
SKS_DEBUG(size << " new client(s) accepted; there are now " <<
activeClientCount << " active client(s)");
@@ -818,10 +822,16 @@
unsigned int ret = uintToString(client->number, buf, size - 1);
buf[ret] = '\0';
return ret;
}
+ string getClientName(const Client *client) {
+ char buf[128];
+ unsigned int size = getClientName(client, buf, sizeof(buf));
+ return string(buf, size);
+ }
+
vector<ClientRefType> getActiveClients() {
vector<ClientRefType> result;
Client *client;
TAILQ_FOREACH (client, &activeClients, nextClient.activeOrDisconnectedClient) {
@@ -841,20 +851,46 @@
}
}
return NULL;
}
+ Client *lookupClient(const StaticString &clientName) {
+ Client *client;
+
+ TAILQ_FOREACH (client, &activeClients, nextClient.activeOrDisconnectedClient) {
+ P_ASSERT_EQ(client->getConnState(), Client::ACTIVE);
+ char buf[512];
+ unsigned int size;
+
+ size = getClientName(client, buf, sizeof(buf));
+ if (StaticString(buf, size) == clientName) {
+ return client;
+ }
+ }
+ return NULL;
+ }
+
bool disconnect(int fd) {
assert(serverState != FINISHED_SHUTDOWN);
Client *client = lookupClient(fd);
if (client != NULL) {
return disconnect(&client);
} else {
return false;
}
}
+ bool disconnect(const StaticString &clientName) {
+ assert(serverState != FINISHED_SHUTDOWN);
+ Client *client = lookupClient(clientName);
+ if (client != NULL) {
+ return disconnect(&client);
+ } else {
+ return false;
+ }
+ }
+
bool disconnect(Client **client) {
Client *c = *client;
if (c->getConnState() != Client::ACTIVE) {
return false;
}
@@ -872,9 +908,10 @@
deinitializeClient(c);
SKC_TRACE(c, 2, "Closing client file descriptor: " << fdnum);
try {
safelyClose(fdnum);
+ P_LOG_FILE_DESCRIPTOR_CLOSE(fdnum);
} catch (const SystemException &e) {
SKC_WARN(c, "An error occurred while closing the client file descriptor: " <<
e.what() << " (errno=" << e.code() << ")");
}