version 1.130, 2008/02/27 20:21:17
|
version 1.136, 2008/08/07 18:03:48
|
|
|
#include "Socket.h" | #include "Socket.h" |
#include <Pegasus/Common/Tracer.h> | #include <Pegasus/Common/Tracer.h> |
#include <Pegasus/Common/HTTPConnection.h> | #include <Pegasus/Common/HTTPConnection.h> |
|
#include <Pegasus/Common/HTTPAcceptor.h> |
#include <Pegasus/Common/MessageQueueService.h> | #include <Pegasus/Common/MessageQueueService.h> |
#include <Pegasus/Common/Exception.h> | #include <Pegasus/Common/Exception.h> |
#include "ArrayIterator.h" | #include "ArrayIterator.h" |
#include "HostAddress.h" | #include "HostAddress.h" |
|
#include <errno.h> |
| |
PEGASUS_USING_STD; | PEGASUS_USING_STD; |
| |
|
|
_uninitialize(); | _uninitialize(); |
} | } |
| |
|
void Tickler::notify() |
|
{ |
|
Socket::write(_clientSocket, "\0", 1); |
|
} |
|
|
|
void Tickler::reset() |
|
{ |
|
// Clear all bytes from the tickle socket |
|
char buffer[32]; |
|
while (Socket::read(_serverSocket, buffer, 32) > 0) |
|
{ |
|
} |
|
} |
|
|
#if defined(PEGASUS_OS_TYPE_UNIX) | #if defined(PEGASUS_OS_TYPE_UNIX) |
| |
// Use an anonymous pipe for the tickle connection. | // Use an anonymous pipe for the tickle connection. |
|
|
| |
_serverSocket = fds[0]; | _serverSocket = fds[0]; |
_clientSocket = fds[1]; | _clientSocket = fds[1]; |
|
|
|
Socket::disableBlocking(_serverSocket); |
} | } |
| |
#else | #else |
|
|
} | } |
catch (...) | catch (...) |
{ | { |
PEG_TRACE_CSTRING(TRC_HTTP, Tracer::LEVEL4, |
PEG_TRACE_CSTRING(TRC_HTTP, Tracer::LEVEL2, |
"Failed to close tickle sockets"); | "Failed to close tickle sockets"); |
} | } |
Socket::uninitializeInterface(); | Socket::uninitializeInterface(); |
|
|
// Create a MonitorEntry for the Tickler and set its state to IDLE so the | // Create a MonitorEntry for the Tickler and set its state to IDLE so the |
// Monitor will watch for its events. | // Monitor will watch for its events. |
_entries.append(MonitorEntry( | _entries.append(MonitorEntry( |
_tickler.getServerSocket(), |
_tickler.getReadHandle(), |
1, | 1, |
MonitorEntry::STATUS_IDLE, | MonitorEntry::STATUS_IDLE, |
MonitorEntry::TYPE_INTERNAL)); |
MonitorEntry::TYPE_TICKLER)); |
| |
// Start the count at 1 because _entries[0] is the Tickler | // Start the count at 1 because _entries[0] is the Tickler |
for (int i = 1; i < numberOfMonitorEntriesToAllocate; i++) | for (int i = 1; i < numberOfMonitorEntriesToAllocate; i++) |
|
|
| |
void Monitor::tickle() | void Monitor::tickle() |
{ | { |
Socket::write(_tickler.getClientSocket(), "\0", 1); |
_tickler.notify(); |
} | } |
| |
void Monitor::setState( | void Monitor::setState( |
|
|
continue; | continue; |
} | } |
h._connectionClosePending = false; | h._connectionClosePending = false; |
MessageQueue &o = h.get_owner(); |
HTTPAcceptor &o = h.getOwningAcceptor(); |
Message* message= new CloseConnectionMessage(entry.socket); | Message* message= new CloseConnectionMessage(entry.socket); |
message->dest = o.getQueueId(); | message->dest = o.getQueueId(); |
| |
|
|
| |
if (events == PEGASUS_SOCKET_ERROR) | if (events == PEGASUS_SOCKET_ERROR) |
{ | { |
PEG_TRACE((TRC_HTTP, Tracer::LEVEL4, |
PEG_TRACE((TRC_HTTP, Tracer::LEVEL1, |
"Monitor::run - select() returned error %d.", selectErrno)); | "Monitor::run - select() returned error %d.", selectErrno)); |
// The EBADF error indicates that one or more or the file | // The EBADF error indicates that one or more or the file |
// descriptions was not valid. This could indicate that | // descriptions was not valid. This could indicate that |
|
|
} | } |
catch (...) | catch (...) |
{ | { |
PEG_TRACE_CSTRING(TRC_HTTP, Tracer::LEVEL2, |
PEG_TRACE_CSTRING(TRC_HTTP, Tracer::LEVEL1, |
"Caught exception from " | "Caught exception from " |
"HTTPConnection::run()"); | "HTTPConnection::run()"); |
} | } |
PEG_TRACE_CSTRING(TRC_HTTP, Tracer::LEVEL4, | PEG_TRACE_CSTRING(TRC_HTTP, Tracer::LEVEL4, |
"Exited HTTPConnection::run()"); | "Exited HTTPConnection::run()"); |
} | } |
|
|
|
|
} | } |
else if (entries[indx].type == MonitorEntry::TYPE_INTERNAL) |
else if (entries[indx].type == MonitorEntry::TYPE_TICKLER) |
{ | { |
char buffer; |
_tickler.reset(); |
Sint32 ignored = |
|
Socket::read(entries[indx].socket, &buffer, 1); |
|
} | } |
else | else |
{ | { |
|
|
"Non-connection entry, indx = %d, has been " | "Non-connection entry, indx = %d, has been " |
"received.", | "received.", |
indx)); | indx)); |
int events = 0; |
|
events |= SocketMessage::READ; |
|
Message* msg = new SocketMessage( | Message* msg = new SocketMessage( |
entries[indx].socket, events); |
entries[indx].socket, SocketMessage::READ); |
entries[indx].status = MonitorEntry::STATUS_BUSY; | entries[indx].status = MonitorEntry::STATUS_BUSY; |
_entriesMutex.unlock(); | _entriesMutex.unlock(); |
q->enqueue(msg); | q->enqueue(msg); |
|
|
| |
{ | { |
MessageQueue* q = MessageQueue::lookup(entries[indx].queueId); | MessageQueue* q = MessageQueue::lookup(entries[indx].queueId); |
|
PEGASUS_ASSERT(q != 0); |
HTTPConnection *dst = reinterpret_cast<HTTPConnection *>(q); | HTTPConnection *dst = reinterpret_cast<HTTPConnection *>(q); |
dst->_entry_index = indx; | dst->_entry_index = indx; |
dst->closeConnectionOnTimeout(&timeNow); | dst->closeConnectionOnTimeout(&timeNow); |
|
|
entries[indx].type == MonitorEntry::TYPE_CONNECTION) | entries[indx].type == MonitorEntry::TYPE_CONNECTION) |
{ | { |
MessageQueue* q = MessageQueue::lookup(entries[indx].queueId); | MessageQueue* q = MessageQueue::lookup(entries[indx].queueId); |
|
PEGASUS_ASSERT(q != 0); |
HTTPConnection *dst = reinterpret_cast<HTTPConnection *>(q); | HTTPConnection *dst = reinterpret_cast<HTTPConnection *>(q); |
dst->_entry_index = indx; | dst->_entry_index = indx; |
dst->closeConnectionOnTimeout(&timeNow); | dst->closeConnectionOnTimeout(&timeNow); |