[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Class relationships...
... I almost hesitate to present this because the ideas involved are
__very__ rough, so please be forgiving. What follows is my vision of the
class
relationships involved in a Web server and a rough sketch on how they might be
implemented. There is very little detail, as I was mainly interested in
soliciting comments and stimulating discussion.
Here goes... be gentle...
void main () {
... start x threads ...
int process_requests () {
Connection my_connection;
my_connection.getRequest(my_connection);
my_connection.processRequest();
my_connection.writeRequest();
}
... assign each thread process_requests() ...
}
Guess this should be "standalone_main", huh? :)
Obviously, this model uses the start-to-end threading model. I do not
wish to suggest that other models should not be considered, but this was
the model I was using when I created these notes.
==============================================================
class Connection {
public:
Connection();
getRequest();
processRequest();
writeRequest();
private:
/*
* This is the current request being serviced by this connection. This
* can change over time if pipelined HTTP/1.1 requests are received.
Request my_request;
Socket my_socket;
/* Connection-level data goes here */
}
Connection::getRequest() {
... set up the accept() call ...
... acquire the mutex ...
my_socket.doSocketAccept(my_socket.something, my_socket.somethingElse);
... release the mutex ASAP ...
}
Michael, I hope this illustrates how we avoid the need for any sort of
message queue abstraction. By blocking on the call to accept(),
encapsulated by the Socket object's member function, we don't need to store
messages ourselves... it's done externally. Seems to me this might be a
performance problem on very busy sites (or really lame TCP/IP stacks), but
it apparently hasn't been for Apache, so I'm not terribly concerned.
==================================================================
Connection "has a" Request
class Request {
public:
private:
/* Request-level data goes here */
};
Like I said, this is horribly incomplete.
==================================================================
Connection "has a" Socket
class Socket {
public:
/*
* OO dogma requires that the Socket member function associated with
* accept() basically do nothing other than call accept(). Any other
* external stuff should be done by the Connection object before this
* member function is called.
*/
doSocketAccept();
private:
}
Maybe this is just restating obvious information that everyone already
knew, but at least maybe we can begin to discuss the failings of these
ideas... and how we can do it better.
- Bret -