Implemented Util::Config::serveForkedSocket(), added Socket::Connection::drop() function for dropping unused sockets.

This commit is contained in:
Thulinma 2014-01-27 18:02:58 +01:00
parent 92b7a7534d
commit d81bc24155
4 changed files with 95 additions and 17 deletions

View file

@ -238,11 +238,23 @@ bool Socket::Connection::isBlocking(){
/// Close connection. The internal socket is closed and then set to -1.
/// If the connection is already closed, nothing happens.
/// This function calls shutdown, thus making the socket unusable in all other
/// processes as well. Do not use on shared sockets that are still in use.
void Socket::Connection::close(){
if (sock != -1){
shutdown(sock, SHUT_RDWR);
}
drop();
} //Socket::Connection::close
/// Close connection. The internal socket is closed and then set to -1.
/// If the connection is already closed, nothing happens.
/// This function does *not* call shutdown, allowing continued use in other
/// processes.
void Socket::Connection::drop(){
if (connected()){
DEBUG_MSG(DLVL_HIGH, "Socket %d closed", sock);
if (sock != -1){
shutdown(sock, SHUT_RDWR);
DEBUG_MSG(DLVL_HIGH, "Socket %d closed", sock);
errno = EINTR;
while (::close(sock) != 0 && errno == EINTR){
}
@ -261,7 +273,7 @@ void Socket::Connection::close(){
pipes[1] = -1;
}
}
} //Socket::Connection::close
} //Socket::Connection::drop
/// Returns internal socket number.
int Socket::Connection::getSocket(){
@ -846,17 +858,31 @@ bool Socket::Server::isBlocking(){
/// Close connection. The internal socket is closed and then set to -1.
/// If the connection is already closed, nothing happens.
/// This function calls shutdown, thus making the socket unusable in all other
/// processes as well. Do not use on shared sockets that are still in use.
void Socket::Server::close(){
if (connected()){
DEBUG_MSG(DLVL_HIGH, "ServerSocket %d closed", sock);
if (sock != -1){
shutdown(sock, SHUT_RDWR);
errno = EINTR;
while (::close(sock) != 0 && errno == EINTR){
}
sock = -1;
}
drop();
} //Socket::Server::close
/// Close connection. The internal socket is closed and then set to -1.
/// If the connection is already closed, nothing happens.
/// This function does *not* call shutdown, allowing continued use in other
/// processes.
void Socket::Server::drop(){
if (connected()){
if (sock != -1){
DEBUG_MSG(DLVL_HIGH, "ServerSocket %d closed", sock);
errno = EINTR;
while (::close(sock) != 0 && errno == EINTR){
}
sock = -1;
}
}
} //Socket::Server::drop
/// Returns the connected-state for this socket.
/// Note that this function might be slightly behind the real situation.
/// The connection status is updated after every accept attempt, when errors occur