[Delivery-boy-cvs] client/DeliveryBoyC/classes clsEasySocket.cs,1.9,1.10 clsEasyTCPServer.cs,1.3,1.4
Status: Planning
Brought to you by:
mkloubert
From: Marcel K. <gen...@us...> - 2005-02-05 00:08:49
|
Update of /cvsroot/delivery-boy/client/DeliveryBoyC/classes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32120/DeliveryBoyC/classes Modified Files: clsEasySocket.cs clsEasyTCPServer.cs Log Message: - removed socket sample code - bugfix in clsEasySocket: set socket to non-blocking at initializing - added some important funcs and properties Index: clsEasyTCPServer.cs =================================================================== RCS file: /cvsroot/delivery-boy/client/DeliveryBoyC/classes/clsEasyTCPServer.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** clsEasyTCPServer.cs 4 Feb 2005 22:33:20 -0000 1.3 --- clsEasyTCPServer.cs 5 Feb 2005 00:08:30 -0000 1.4 *************** *** 23,26 **** --- 23,27 ---- using System; + using System.Collections; /*! \class clsEasyTCPServer clsEasyTCPServer.cs "clsEasyTCPServer.cs" *************** *** 42,45 **** --- 43,51 ---- * \note * $Log$ + * Revision 1.4 2005/02/05 00:08:30 generalpd + * - removed socket sample code + * - bugfix in clsEasySocket: set socket to non-blocking at initializing + * - added some important funcs and properties + * * Revision 1.3 2005/02/04 22:33:20 generalpd * - changed combine options: Compiler is Mono and Runtime-Env is Microsoft .NET *************** *** 56,64 **** public class clsEasyTCPServer { ! clsEasySocket[] m_oSockets; public clsEasyTCPServer() { ! m_oSockets = new clsEasySocket[0]; } } --- 62,263 ---- public class clsEasyTCPServer { ! /// Default listen queue size ! private const Int32 DEFAULT_LISTENQUEUE_SIZE = 16; ! ! /// Listen socket ! private clsEasySocket m_oListenSocket; ! /// Local port ! private Int32 m_i32Port = -1; ! /// Last occurred exception ! private Exception m_oLastException = null; ! /// Listen queue size ! private Int32 m_i32ListenQueue = -1; + /// Connections + private ArrayList m_oConnections = null; + + /*! \fn public clsEasyTCPServer + * \brief Inits all necessary stuff + * + * \param (none) + * + * \return (none) + */ public clsEasyTCPServer() { ! m_oListenSocket = null; ! Port = 0; ! ListenQueue = DEFAULT_LISTENQUEUE_SIZE; ! ! m_oConnections = new ArrayList(); ! } ! ! /*! \property public Int32 ListenQueue ! * \brief Returns the size of the listen queue or sets it. ! * ! * \param value New size ! * ! * \return Size of listen queue ! */ ! public Int32 ListenQueue ! { ! get ! { ! return m_i32ListenQueue; ! } ! ! set ! { ! m_i32ListenQueue = value; ! } ! } ! ! /*! \fn public Int32 Port ! * \brief Return or set the port of this server ! * ! * \param value New port ! * ! * \return Port ! */ ! public Int32 Port ! { ! get ! { ! return m_i32Port; ! } ! ! set ! { ! m_oListenSocket.LocalPort = value; ! m_i32Port = m_oListenSocket.LocalPort; ! } ! } ! ! /*! \fn public bool Listening ! * \brief Return if this server is listening ! * ! * \param (none) ! * ! * \return Is listening (true) or not (false) ! */ ! public bool Listening ! { ! get ! { ! return m_oListenSocket.Connected; ! } ! } ! ! /*! \fn public UInt32 Stop () ! * \brief Stops the server. ! * ! * \param (none) ! * ! * \return Error code:<BR> ! * 0 => no error<BR> ! * 1 => general exception<BR> ! * 2 => not listening ! */ ! public UInt32 Stop () ! { ! try ! { ! if (!Listening) ! { ! // not listening ! return SetLastException(2, null); ! } ! else ! { ! if ( 0 == m_oListenSocket.Close()) ! { ! m_oListenSocket = null; ! return SetLastException(0, null); ! } ! else ! // socket error ! return SetLastException(3, m_oListenSocket.LastException); ! } ! } ! catch (Exception e) ! { ! return SetLastException(1, e); ! } ! } ! ! /*! \fn public UInt32 Start () ! * \brief Starts the server. ! * ! * \param (none) ! * ! * \return Error code:<BR> ! * 0 => no error<BR> ! * 1 => general exception<BR> ! * 2 => already listening ! */ ! public UInt32 Start () ! { ! try ! { ! if (Listening) ! { ! m_oListenSocket = null; ! ! // already listening ! return SetLastException(2, null); ! } ! else ! { ! m_oListenSocket = new clsEasySocket(); ! m_oListenSocket.LocalPort = Port; ! m_oListenSocket.ListenQueue = DEFAULT_LISTENQUEUE_SIZE; ! ! if ( 0 == m_oListenSocket.Listen()) ! return SetLastException(0, null); ! else ! { ! m_oListenSocket = null; ! ! // socket error ! return SetLastException(3, m_oListenSocket.LastException); ! } ! } ! } ! catch (Exception e) ! { ! m_oListenSocket = null; ! ! return SetLastException(1, e); ! } ! } ! ! /*! \property public Exception LastException ! * \brief Returns the last occurred exception. ! * ! * \param (none) ! * ! * \return Exception object (null => no error) ! */ ! public Exception LastException ! { ! get ! { ! return m_oLastException; ! } ! } ! ! /*! \fn private UInt32 SetLastException (UInt32 ui32_ErrorCode, Exception oNewException) ! * \brief Sets the last occurred exception. ! * ! * \param ui32_ErrorCode Error code. ! * \param oNewException The new exception object. ! * ! * \return Error code submitted by ui32_ErrorCode ! */ ! private UInt32 SetLastException (UInt32 ui32_ErrorCode, Exception oNewException) ! { ! m_oLastException = oNewException; ! ! return ui32_ErrorCode; } } Index: clsEasySocket.cs =================================================================== RCS file: /cvsroot/delivery-boy/client/DeliveryBoyC/classes/clsEasySocket.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** clsEasySocket.cs 4 Feb 2005 20:20:39 -0000 1.9 --- clsEasySocket.cs 5 Feb 2005 00:08:30 -0000 1.10 *************** *** 43,46 **** --- 43,51 ---- * \note * $Log$ + * Revision 1.10 2005/02/05 00:08:30 generalpd + * - removed socket sample code + * - bugfix in clsEasySocket: set socket to non-blocking at initializing + * - added some important funcs and properties + * * Revision 1.9 2005/02/04 20:20:39 generalpd * - changed from * to - to define a point *************** *** 57,60 **** --- 62,67 ---- /// Default buffer size in byte private const Int32 DEFAULT_BUFFER_SIZE = 1024; + /// Default listen queue size + private const Int32 DEFAULT_LISTENQUEUE_SIZE = 16; /// Byte buffer *************** *** 125,131 **** RemoteAddress = "0.0.0.0"; RemotePort = 0; ! ListenQueue = 1; BufferSize = DEFAULT_BUFFER_SIZE; AutoAccept = true; b_Buffer = new byte[BufferSize]; --- 132,139 ---- RemoteAddress = "0.0.0.0"; RemotePort = 0; ! ListenQueue = DEFAULT_LISTENQUEUE_SIZE; BufferSize = DEFAULT_BUFFER_SIZE; AutoAccept = true; + SocketObject.Blocking = false; b_Buffer = new byte[BufferSize]; *************** *** 243,247 **** * \return Socket object */ ! public Socket SocketObject { get --- 251,255 ---- * \return Socket object */ ! public System.Net.Sockets.Socket SocketObject { get *************** *** 363,366 **** --- 371,375 ---- else { + SocketObject.Shutdown(SocketShutdown.Both); SocketObject.Close(); *************** *** 558,562 **** { int iBytesRead = SocketObject.EndReceive(ar); ! if (null != OnReceive) this.OnReceive(this, b_Buffer, iBytesRead); --- 567,571 ---- { int iBytesRead = SocketObject.EndReceive(ar); ! if (null != OnReceive) this.OnReceive(this, b_Buffer, iBytesRead); |