//Download by http://www.NewXing.com
///////////////////////////////////////////////////////////////////////////////
//
// File : $Workfile: SocketServer.cpp $
// Version : $Revision: 42 $
// Function :
//
// Author : $Author: Len $
// Date : $Date: 13/08/02 9:46 $
//
// Notes :
//
// Modifications :
//
// $Log: /Web Articles/SocketServers/EchoServer/JetByteTools/Win32Tools/SocketServer.cpp $
//
// 42 13/08/02 9:46 Len
// Recognise WSAECONNABORTED as a connection reset error.
//
// 41 12/08/02 12:04 Len
// Lint issues.
//
// 40 12/08/02 11:41 Len
// The derived class is now informed when a client resets the connection.
// The user of a socket can check to see if it's connected (in either
// direction) Read and Write calls on a disconnected socket now report
// their failure.
//
// 39 12/08/02 9:26 Len
// Started to change how we handle read/write errors.
//
// 38 10/08/02 13:19 Len
// Clean up socket's use of critical section. For now we're keeping the
// per socket critical section...
//
// 37 9/08/02 13:04 Len
// Lint issues.
//
// 36 6/08/02 17:40 Len
// Added a helper method, IsValid(), which does the check for
// (INVALID_SOCKET != m_socket) and locks appropriately so as to remove
// the race conditions during socket closure.
// We now don't call the OnClientClose() notification unless the client
// has closed the socket - we used to call it even if the socket closure
// was due to the server closing the socket.Thanks to David McConnell for
// reporting both issues and suggesting the fixes.
//
// 35 6/08/02 11:50 Len
// All calls to Output() are now wrapped in a DEBUG_ONLY() macro so they
// vanish completely from release builds.
// Switched to using a critical section per socket to do some quick
// performance comparison tests.
//
// 34 22/07/02 18:27 Len
// Added helper class that makes it easier to write servers that perform
// their filtering on a thread other than an IO thread.
//
// 33 17/07/02 10:56 Len
// Allow derived classes more scope to override some operations.
//
// 32 15/07/02 9:53 Len
// Added the concept of posting 0 byte reads (for servers with lots of
// connected clients, so we dont use up the non-paged pool). When a 0 byte
// read completes it means that data can be read immediately, so we issue
// a normal read.
// Fixed a race condition between the assignment of the read sequence
// number and the issuing of the read.
//
// 31 9/07/02 19:22 Len
// Bug fix. We were using the filtered read sequence number when we should
// have been using the unfiltered read sequence number.
//
// 30 9/07/02 18:33 Len
// Use of sequence numbers is now optional.
//
// 29 6/07/02 14:08 Len
// All buffers sent and received now contain sequence numbers. These are
// maintained on a per socket basis. To allow filters to add/remove
// individual reads/writes yet still be able to ensure that they process
// the application's read/write requests in the correct sequence there are
// pre and post filtering sequence numbers. All socket writes now check
// the sequence numbers to ensure that buffers are transmitted in the
// correct sequence, this is required because we post our write requests
// to the io thread pool and though they come out of the IOCP in the
// correct order, if there are multiple threads in the io pool then they
// could be transmitted out of sequence.
//
// 28 4/07/02 15:43 Len
// Fixes to how we use WritePending.
//
// 27 1/07/02 22:33 Len
// Added the concept of 'filtering'. A derived class can now opt to filter
// certain operations, such as a read completion. This allows a derived
// class to process the data before it is passed to the ReadComplete()
// event. This is useful for such things as ensuring that multiple
// outstanding reads complete in the order that they were issued, or
// adding encryption to the data stream below the application level.
//
// 26 29/06/02 18:25 Len
// Moved all callbacks to the SocketServer class. We now provide a default
// implementation for the WorkerThread. This raises its events via the
// socket server. The user now only has to provide one derived class
// rather than two. We now provide a default implementation for listening
// socket creation.
//
// 25 28/06/02 13:44 Len
// Allow derived class to intercept socket closure and inform derived
// class of client closure.
//
// 24 27/06/02 16:05 Len
// Fixed how we handle socket closure. We now handle the client sending a
// recv shutdown correctly and allow the server code to issue a send
// shutdown and for it to be actioned after all pending writes have been
// sent.
//
// 23 7/06/02 14:15 Len
// Changes due to change in CIOBuffer. The buffer now derives from
// OVERLAPPED so the explicit conversion functions are no longer required.
//
// 22 5/06/02 19:17 Len
// Abortive socket closure is now done by an IO pool worker thread. This
// is a workaround for a problem with the COM wrapper.
//
// 21 29/05/02 12:05 Len
// Lint issues.
//
// 20 26/05/02 15:10 Len
// Factored out common 'user data' code into a mixin base class.
//
// 19 24/05/02 12:13 Len
// Refactored all the linked list stuff for the sockets into a NodeList
// class.
//
// 18 21/05/02 11:36 Len
// User data can now be stored/retrieved as either an unsigned long or a
// void *.
// A CIOBuffer containing the client's address is now passed with
// OnConnectionEstablished().
//
// 17 21/05/02 8:33 Len
// Allow derived class to flush buffer allocator in destructor so that it
// can receive notifications about buffer release.
//
// 16 21/05/02 8:05 Len
// SocketServer now derives from the buffer allocator.
//
// 15 20/05/02 23:17 Len
// Updated copyright and disclaimers.
//
// 14 20/05/02 17:26 Len
// Merged OnNewConnection() into OnConnectionEstablished().
// We now pass the socket to OnConnectionClosed() so that the derived
// class can dealocate any per connection user data when the connection is
// closed.
//
// 13 20/05/02 14:45 Len
// SocketServer doesn't need to pass allocator to WorkerThread.
//
// 12 20/05/02 14:38 Len
// WorkerThread never needs to use the allocator.
//
// 11 20/05/02 8:09 Len
// Moved the concept of the io operation used for the io buffer into the
// socket server. The io buffer now simply presents 'user data' access
// functions. Added a similar concept of user data to the socket class so
// that users can associate their own data with a connection . Derived
// class is now notified when a connection occurs so that they can send a
// greeting or request a read, etc.
// General code cleanup and refactoring.
//
// 10 16/05/02 21:35 Len
// Users now signal that we're finished with a socket by calling
// Shutdown() rather than Close().
//
// 9 15/05/02 11:07 Len
// TX and RX data logging are now wrapped in a DEBUG_ONLY() macro as the
// call to DumpData() was occurring even though the output wasnt being
// logged. This change almost doubled the throughput of the server...
//
// 8 15/05/02 10:45 Len
// Enabled TX and RX data logging in debug build
//
// 7 14/05/02 14:37 Len
// Expose CThread::Start() using a using declaration rather than a
// forwarding function.
// Lint cleanup.
//
// 6 14/05/02 13:53 Len
// We now explicitly start the thread pool rather than allowing it to
// start itself in the constructor. There was a race condition over the
// completion of construction of derived classes and the first access to
// the pure virtual functions.
// Refactored some of the socket code to improve encapsulation.
//
// 5 13/05/02 13:44 Len
// Added OnError() methods so that derived class can do something about
// obscure error situations.
// Added a 'max free socke
评论17
最新资源