From 852eab4605ad0d832c38b5ee69bf49c5417821c0 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:05:39 +0000 Subject: Utilisateur : Fcolin Date : 16/06/00 Heure : 10:14 Créé (vss 1) --- Ivy/ThreadedSocket.h | 169 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 Ivy/ThreadedSocket.h (limited to 'Ivy/ThreadedSocket.h') diff --git a/Ivy/ThreadedSocket.h b/Ivy/ThreadedSocket.h new file mode 100644 index 0000000..19fca4f --- /dev/null +++ b/Ivy/ThreadedSocket.h @@ -0,0 +1,169 @@ +// ThreadedSocket.h: interface for the CThreadedSocket class. +// +////////////////////////////////////////////////////////////////////// + +#if !defined(AFX_THREADEDSOCKET_H__DC45EFD8_343F_11D3_8A15_00A0245B298A__INCLUDED_) +#define AFX_THREADEDSOCKET_H__DC45EFD8_343F_11D3_8A15_00A0245B298A__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +#include + +class CThreadedSocketException //: public CException +{ +// DECLARE_DYNAMIC(CThreadedSocketException) +public: +// Constructor + CThreadedSocketException(char* pchMessage); + +public: + ~CThreadedSocketException() {} + virtual bool GetErrorMessage(string& lpstrError, unsigned int nMaxError, + unsigned int * pnHelpContext = 0); + int GetError() { return m_nError; }; +private: + int m_nError; + char * m_strMessage; +}; + +class CThreadedSocket //: public CObject +{ +// DECLARE_DYNAMIC(CThreadedSocket); +// typedef unsigned int SOCKET; +// typedef struct sockaddr SOCKADDR; + +public: + CThreadedSocket(); + virtual ~CThreadedSocket(); +// Construction +public: + void Create(unsigned int nSocketPort = 0, int nSocketType=SOCK_STREAM, + long lEvent = FD_READ | FD_WRITE | FD_OOB | FD_ACCEPT | FD_CONNECT | FD_CLOSE, + const char * lpszSocketAddress = 0); + +// Attributes +public: + SOCKET m_hSocket; + + operator SOCKET() const; + + void GetPeerName(string & rPeerAddress, unsigned int& rPeerPort); + + void GetSockName(string & rSocketAddress, unsigned int& rSocketPort); + +// Operations +public: + void Socket(int nSocketType=SOCK_STREAM, long lEvent = + FD_READ | FD_WRITE | FD_OOB | FD_ACCEPT | FD_CONNECT | FD_CLOSE, + int nProtocolType = 0, int nAddressFormat = PF_INET); + virtual void Accept(CThreadedSocket& rConnectedSocket, + SOCKADDR* lpSockAddr = NULL, int* lpSockAddrLen = NULL); + + void Bind(unsigned int nSocketPort, const char * lpszSocketAddress = 0); + + virtual void Close(); + + bool Connect(const char * lpszHostAddress, unsigned int nHostPort); + bool Connect(const SOCKADDR* lpSockAddr, int nSockAddrLen); + + virtual int Receive(void* lpBuf, int nBufLen, int nFlags = 0); + + int ReceiveFrom(void* lpBuf, int nBufLen, + string & rSocketAddress, unsigned int & rSocketPort, int nFlags = 0); + + enum { receives = 0, sends = 1, both = 2 }; + + virtual void Send(const void* lpBuf, int nBufLen, int nFlags = 0); + + void SendTo(const void* lpBuf, int nBufLen, + unsigned int nHostPort, const char * lpszHostAddress = 0, int nFlags = 0); + void AsyncSelect(long lEvent = + FD_READ | FD_WRITE | FD_OOB | FD_ACCEPT | FD_CONNECT | FD_CLOSE); + + +inline CThreadedSocket::operator SOCKET() const + { return m_hSocket; } +inline void GetPeerName(SOCKADDR* lpSockAddr, int* lpSockAddrLen) + { + if ( getpeername(m_hSocket, lpSockAddr, lpSockAddrLen) == SOCKET_ERROR) + throw( new CThreadedSocketException( "getpeername" ) ); + } +inline void GetSockName(SOCKADDR* lpSockAddr, int* lpSockAddrLen) + { if ( getsockname(m_hSocket, lpSockAddr, lpSockAddrLen)== SOCKET_ERROR) + throw( new CThreadedSocketException( "getsockname" ) ); + } +inline void SetSockOpt(int nOptionName, const void* lpOptionValue, int nOptionLen, int nLevel = SOL_SOCKET) + { + if ( setsockopt(m_hSocket, nLevel, nOptionName, (LPCSTR)lpOptionValue, nOptionLen)== SOCKET_ERROR) + throw( new CThreadedSocketException( "setsockopt" ) ); + } +inline void GetSockOpt(int nOptionName, void* lpOptionValue, int* lpOptionLen, int nLevel = SOL_SOCKET) + { + if ( getsockopt(m_hSocket, nLevel, nOptionName, (LPSTR)lpOptionValue, lpOptionLen)== SOCKET_ERROR) + throw( new CThreadedSocketException( "getsockopt" ) ); + } + +static inline int CThreadedSocket::GetLastError() + { return WSAGetLastError(); } +inline void Bind(const SOCKADDR* lpSockAddr, int nSockAddrLen) + { + if ( bind(m_hSocket, lpSockAddr, nSockAddrLen)== SOCKET_ERROR ) + throw( new CThreadedSocketException( "bind" )); + } + +inline void IOCtl(long lCommand, unsigned long* lpArgument) + { if ( ioctlsocket(m_hSocket, lCommand, lpArgument)== SOCKET_ERROR) + throw( new CThreadedSocketException( "bind" ) ); + } +inline void Listen(int nConnectionBacklog=5) + { + if ( listen(m_hSocket, nConnectionBacklog)== SOCKET_ERROR) + throw( new CThreadedSocketException( "listen" ) ); + } +inline int ReceiveFrom(void* lpBuf, int nBufLen, SOCKADDR* lpSockAddr, int* lpSockAddrLen, int nFlags = 0) + { + int lg = recvfrom(m_hSocket, (LPSTR)lpBuf, nBufLen, nFlags, lpSockAddr, lpSockAddrLen); + if ( lg == SOCKET_ERROR ) + throw( new CThreadedSocketException( "recvfrom" ) ); + return lg; + } +inline bool ShutDown(int nHow = sends) + { + if ( shutdown(m_hSocket,nHow) == SOCKET_ERROR ) + throw( new CThreadedSocketException( "shutdown" ) ); + } +inline void SendTo(const void* lpBuf, int nBufLen, const SOCKADDR* lpSockAddr, int nSockAddrLen, int nFlags = 0) + { + if ( sendto(m_hSocket, (LPSTR)lpBuf, nBufLen, nFlags, lpSockAddr, nSockAddrLen)== SOCKET_ERROR ) + throw( new CThreadedSocketException( "sendto" ) ); + } + + + +// Overridable callbacks +protected: + virtual void OnWakeup(); + virtual void OnReceive(int nErrorCode); + virtual void OnSend(int nErrorCode); + virtual void OnOutOfBandData(int nErrorCode); + virtual void OnAccept(int nErrorCode); + virtual void OnConnect(int nErrorCode); + virtual void OnClose(int nErrorCode); +// Implementation + void StartListener(long lEvent); + long m_EventMask; + unsigned long thread_id; + HANDLE h_thread; + WSAEVENT m_hEvent[2]; // socket event for receive and send actions + unsigned int SocketThread(); //Client Thread + +// wrapper for thread routine +static DWORD WINAPI SocketThreadProc( void * pParam ); +static void Init(); +static bool Initialized; + +}; + +#endif // !defined(AFX_THREADEDSOCKET_H__DC45EFD8_343F_11D3_8A15_00A0245B298A__INCLUDED_) -- cgit v1.1 From 4b8a6b79df9e4433fff614c786441b75f52bcddc Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:05:40 +0000 Subject: Utilisateur : Fcolin Date : 16/06/00 Heure : 10:40 Archivé dans $/Ivy Commentaire: Init dll socket dans DLLMain (vss 2) --- Ivy/ThreadedSocket.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'Ivy/ThreadedSocket.h') diff --git a/Ivy/ThreadedSocket.h b/Ivy/ThreadedSocket.h index 19fca4f..1a3f405 100644 --- a/Ivy/ThreadedSocket.h +++ b/Ivy/ThreadedSocket.h @@ -161,8 +161,6 @@ protected: // wrapper for thread routine static DWORD WINAPI SocketThreadProc( void * pParam ); -static void Init(); -static bool Initialized; }; -- cgit v1.1 From 99d788dbb3bad0d82be026054d88f9245b0c5bcf Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:05:42 +0000 Subject: Utilisateur : Fcolin Date : 29/06/00 Heure : 15:59 Archivé dans $/Ivy Commentaire: Version multicast (vss 3) --- Ivy/ThreadedSocket.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Ivy/ThreadedSocket.h') diff --git a/Ivy/ThreadedSocket.h b/Ivy/ThreadedSocket.h index 1a3f405..2fbe8c8 100644 --- a/Ivy/ThreadedSocket.h +++ b/Ivy/ThreadedSocket.h @@ -58,6 +58,9 @@ public: void Socket(int nSocketType=SOCK_STREAM, long lEvent = FD_READ | FD_WRITE | FD_OOB | FD_ACCEPT | FD_CONNECT | FD_CLOSE, int nProtocolType = 0, int nAddressFormat = PF_INET); + + void AddMember( const char * lpszHostAddress ); + virtual void Accept(CThreadedSocket& rConnectedSocket, SOCKADDR* lpSockAddr = NULL, int* lpSockAddrLen = NULL); -- cgit v1.1 From 3ac6d4f575306385ad90fce0a22901afa301132e Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:05:44 +0000 Subject: Utilisateur : Fcolin Date : 23/01/01 Heure : 13:12 Archivé dans $/Ivy Commentaire: remove 'using name space std;' (vss 4) --- Ivy/ThreadedSocket.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Ivy/ThreadedSocket.h') diff --git a/Ivy/ThreadedSocket.h b/Ivy/ThreadedSocket.h index 2fbe8c8..bcdf8e5 100644 --- a/Ivy/ThreadedSocket.h +++ b/Ivy/ThreadedSocket.h @@ -20,7 +20,7 @@ public: public: ~CThreadedSocketException() {} - virtual bool GetErrorMessage(string& lpstrError, unsigned int nMaxError, + virtual bool GetErrorMessage(String& lpstrError, unsigned int nMaxError, unsigned int * pnHelpContext = 0); int GetError() { return m_nError; }; private: @@ -49,9 +49,9 @@ public: operator SOCKET() const; - void GetPeerName(string & rPeerAddress, unsigned int& rPeerPort); + void GetPeerName(String & rPeerAddress, unsigned int& rPeerPort); - void GetSockName(string & rSocketAddress, unsigned int& rSocketPort); + void GetSockName(String & rSocketAddress, unsigned int& rSocketPort); // Operations public: @@ -74,7 +74,7 @@ public: virtual int Receive(void* lpBuf, int nBufLen, int nFlags = 0); int ReceiveFrom(void* lpBuf, int nBufLen, - string & rSocketAddress, unsigned int & rSocketPort, int nFlags = 0); + String & rSocketAddress, unsigned int & rSocketPort, int nFlags = 0); enum { receives = 0, sends = 1, both = 2 }; -- cgit v1.1 From 1216a6d96c4aa7e76f6999ea39d49d3f444674ac Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:05:46 +0000 Subject: Utilisateur : Fcolin Date : 31/01/01 Heure : 11:18 Archivé dans $/Ivy (vss 5) --- Ivy/ThreadedSocket.h | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) (limited to 'Ivy/ThreadedSocket.h') diff --git a/Ivy/ThreadedSocket.h b/Ivy/ThreadedSocket.h index bcdf8e5..829c562 100644 --- a/Ivy/ThreadedSocket.h +++ b/Ivy/ThreadedSocket.h @@ -2,25 +2,19 @@ // ////////////////////////////////////////////////////////////////////// -#if !defined(AFX_THREADEDSOCKET_H__DC45EFD8_343F_11D3_8A15_00A0245B298A__INCLUDED_) -#define AFX_THREADEDSOCKET_H__DC45EFD8_343F_11D3_8A15_00A0245B298A__INCLUDED_ -#if _MSC_VER > 1000 #pragma once -#endif // _MSC_VER > 1000 -#include - -class CThreadedSocketException //: public CException +class CThreadedSocketException { -// DECLARE_DYNAMIC(CThreadedSocketException) + public: // Constructor CThreadedSocketException(char* pchMessage); public: ~CThreadedSocketException() {} - virtual bool GetErrorMessage(String& lpstrError, unsigned int nMaxError, + virtual bool GetErrorMessage(string& lpstrError, unsigned int nMaxError, unsigned int * pnHelpContext = 0); int GetError() { return m_nError; }; private: @@ -28,11 +22,8 @@ private: char * m_strMessage; }; -class CThreadedSocket //: public CObject +class CThreadedSocket { -// DECLARE_DYNAMIC(CThreadedSocket); -// typedef unsigned int SOCKET; -// typedef struct sockaddr SOCKADDR; public: CThreadedSocket(); @@ -49,9 +40,9 @@ public: operator SOCKET() const; - void GetPeerName(String & rPeerAddress, unsigned int& rPeerPort); + void GetPeerName(string & rPeerAddress, unsigned int& rPeerPort); - void GetSockName(String & rSocketAddress, unsigned int& rSocketPort); + void GetSockName(string & rSocketAddress, unsigned int& rSocketPort); // Operations public: @@ -74,7 +65,7 @@ public: virtual int Receive(void* lpBuf, int nBufLen, int nFlags = 0); int ReceiveFrom(void* lpBuf, int nBufLen, - String & rSocketAddress, unsigned int & rSocketPort, int nFlags = 0); + string & rSocketAddress, unsigned int & rSocketPort, int nFlags = 0); enum { receives = 0, sends = 1, both = 2 }; @@ -91,7 +82,7 @@ inline CThreadedSocket::operator SOCKET() const inline void GetPeerName(SOCKADDR* lpSockAddr, int* lpSockAddrLen) { if ( getpeername(m_hSocket, lpSockAddr, lpSockAddrLen) == SOCKET_ERROR) - throw( new CThreadedSocketException( "getpeername" ) ); + throw ( new CThreadedSocketException( "getpeername" ) ); } inline void GetSockName(SOCKADDR* lpSockAddr, int* lpSockAddrLen) { if ( getsockname(m_hSocket, lpSockAddr, lpSockAddrLen)== SOCKET_ERROR) @@ -166,5 +157,3 @@ protected: static DWORD WINAPI SocketThreadProc( void * pParam ); }; - -#endif // !defined(AFX_THREADEDSOCKET_H__DC45EFD8_343F_11D3_8A15_00A0245B298A__INCLUDED_) -- cgit v1.1 From f65446ec7d815cd429f36c306de5905712ec89af Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:05:48 +0000 Subject: Utilisateur : Fcolin Date : 2/02/01 Heure : 18:30 Archivé dans $/Ivy Commentaire: win CE compile not finished (vss 6) --- Ivy/ThreadedSocket.h | 120 ++++++++++++++++++++++----------------------------- 1 file changed, 51 insertions(+), 69 deletions(-) (limited to 'Ivy/ThreadedSocket.h') diff --git a/Ivy/ThreadedSocket.h b/Ivy/ThreadedSocket.h index 829c562..ab8e3cd 100644 --- a/Ivy/ThreadedSocket.h +++ b/Ivy/ThreadedSocket.h @@ -5,22 +5,7 @@ #pragma once -class CThreadedSocketException -{ - -public: -// Constructor - CThreadedSocketException(char* pchMessage); -public: - ~CThreadedSocketException() {} - virtual bool GetErrorMessage(string& lpstrError, unsigned int nMaxError, - unsigned int * pnHelpContext = 0); - int GetError() { return m_nError; }; -private: - int m_nError; - char * m_strMessage; -}; class CThreadedSocket { @@ -30,9 +15,7 @@ public: virtual ~CThreadedSocket(); // Construction public: - void Create(unsigned int nSocketPort = 0, int nSocketType=SOCK_STREAM, - long lEvent = FD_READ | FD_WRITE | FD_OOB | FD_ACCEPT | FD_CONNECT | FD_CLOSE, - const char * lpszSocketAddress = 0); + int Create(unsigned int nSocketPort = 0, int nSocketType=SOCK_STREAM, const char * lpszSocketAddress = 0); // Attributes public: @@ -46,21 +29,19 @@ public: // Operations public: - void Socket(int nSocketType=SOCK_STREAM, long lEvent = - FD_READ | FD_WRITE | FD_OOB | FD_ACCEPT | FD_CONNECT | FD_CLOSE, - int nProtocolType = 0, int nAddressFormat = PF_INET); + int Socket(int nSocketType=SOCK_STREAM, int nProtocolType = 0, int nAddressFormat = PF_INET); - void AddMember( const char * lpszHostAddress ); + int AddMember( const char * lpszHostAddress ); - virtual void Accept(CThreadedSocket& rConnectedSocket, + virtual int Accept(CThreadedSocket& rConnectedSocket, SOCKADDR* lpSockAddr = NULL, int* lpSockAddrLen = NULL); - void Bind(unsigned int nSocketPort, const char * lpszSocketAddress = 0); + int Bind(unsigned int nSocketPort, const char * lpszSocketAddress = 0); virtual void Close(); - bool Connect(const char * lpszHostAddress, unsigned int nHostPort); - bool Connect(const SOCKADDR* lpSockAddr, int nSockAddrLen); + int Connect(const char * lpszHostAddress, unsigned int nHostPort); + int Connect(const SOCKADDR* lpSockAddr, int nSockAddrLen); virtual int Receive(void* lpBuf, int nBufLen, int nFlags = 0); @@ -69,76 +50,67 @@ public: enum { receives = 0, sends = 1, both = 2 }; - virtual void Send(const void* lpBuf, int nBufLen, int nFlags = 0); + virtual int Send(const void* lpBuf, int nBufLen, int nFlags = 0); - void SendTo(const void* lpBuf, int nBufLen, + int SendTo(const void* lpBuf, int nBufLen, unsigned int nHostPort, const char * lpszHostAddress = 0, int nFlags = 0); - void AsyncSelect(long lEvent = - FD_READ | FD_WRITE | FD_OOB | FD_ACCEPT | FD_CONNECT | FD_CLOSE); + inline CThreadedSocket::operator SOCKET() const { return m_hSocket; } -inline void GetPeerName(SOCKADDR* lpSockAddr, int* lpSockAddrLen) +inline int GetPeerName(SOCKADDR* lpSockAddr, int* lpSockAddrLen) { - if ( getpeername(m_hSocket, lpSockAddr, lpSockAddrLen) == SOCKET_ERROR) - throw ( new CThreadedSocketException( "getpeername" ) ); + return getpeername(m_hSocket, lpSockAddr, lpSockAddrLen); } -inline void GetSockName(SOCKADDR* lpSockAddr, int* lpSockAddrLen) - { if ( getsockname(m_hSocket, lpSockAddr, lpSockAddrLen)== SOCKET_ERROR) - throw( new CThreadedSocketException( "getsockname" ) ); +inline int GetSockName(SOCKADDR* lpSockAddr, int* lpSockAddrLen) + { + return getsockname(m_hSocket, lpSockAddr, lpSockAddrLen); } -inline void SetSockOpt(int nOptionName, const void* lpOptionValue, int nOptionLen, int nLevel = SOL_SOCKET) +inline int SetSockOpt(int nOptionName, const void* lpOptionValue, int nOptionLen, int nLevel = SOL_SOCKET) { - if ( setsockopt(m_hSocket, nLevel, nOptionName, (LPCSTR)lpOptionValue, nOptionLen)== SOCKET_ERROR) - throw( new CThreadedSocketException( "setsockopt" ) ); + return setsockopt(m_hSocket, nLevel, nOptionName, (LPCSTR)lpOptionValue, nOptionLen); } -inline void GetSockOpt(int nOptionName, void* lpOptionValue, int* lpOptionLen, int nLevel = SOL_SOCKET) +inline int GetSockOpt(int nOptionName, void* lpOptionValue, int* lpOptionLen, int nLevel = SOL_SOCKET) { - if ( getsockopt(m_hSocket, nLevel, nOptionName, (LPSTR)lpOptionValue, lpOptionLen)== SOCKET_ERROR) - throw( new CThreadedSocketException( "getsockopt" ) ); + return getsockopt(m_hSocket, nLevel, nOptionName, (LPSTR)lpOptionValue, lpOptionLen); } static inline int CThreadedSocket::GetLastError() - { return WSAGetLastError(); } -inline void Bind(const SOCKADDR* lpSockAddr, int nSockAddrLen) + { return ::WSAGetLastError(); } +inline int Bind(const SOCKADDR* lpSockAddr, int nSockAddrLen) { - if ( bind(m_hSocket, lpSockAddr, nSockAddrLen)== SOCKET_ERROR ) - throw( new CThreadedSocketException( "bind" )); + return bind(m_hSocket, lpSockAddr, nSockAddrLen); } -inline void IOCtl(long lCommand, unsigned long* lpArgument) - { if ( ioctlsocket(m_hSocket, lCommand, lpArgument)== SOCKET_ERROR) - throw( new CThreadedSocketException( "bind" ) ); +inline int IOCtl(long lCommand, unsigned long* lpArgument) + { + return ioctlsocket(m_hSocket, lCommand, lpArgument); } -inline void Listen(int nConnectionBacklog=5) +inline int Listen(int nConnectionBacklog=5) { - if ( listen(m_hSocket, nConnectionBacklog)== SOCKET_ERROR) - throw( new CThreadedSocketException( "listen" ) ); + int err = listen(m_hSocket, nConnectionBacklog); + if ( !err ) + listen_mode = true; + return err; } inline int ReceiveFrom(void* lpBuf, int nBufLen, SOCKADDR* lpSockAddr, int* lpSockAddrLen, int nFlags = 0) { int lg = recvfrom(m_hSocket, (LPSTR)lpBuf, nBufLen, nFlags, lpSockAddr, lpSockAddrLen); - if ( lg == SOCKET_ERROR ) - throw( new CThreadedSocketException( "recvfrom" ) ); return lg; } -inline bool ShutDown(int nHow = sends) +inline int ShutDown(int nHow = sends) { - if ( shutdown(m_hSocket,nHow) == SOCKET_ERROR ) - throw( new CThreadedSocketException( "shutdown" ) ); + return shutdown(m_hSocket,nHow); } -inline void SendTo(const void* lpBuf, int nBufLen, const SOCKADDR* lpSockAddr, int nSockAddrLen, int nFlags = 0) +inline int SendTo(const void* lpBuf, int nBufLen, const SOCKADDR* lpSockAddr, int nSockAddrLen, int nFlags = 0) { - if ( sendto(m_hSocket, (LPSTR)lpBuf, nBufLen, nFlags, lpSockAddr, nSockAddrLen)== SOCKET_ERROR ) - throw( new CThreadedSocketException( "sendto" ) ); + return sendto(m_hSocket, (LPSTR)lpBuf, nBufLen, nFlags, lpSockAddr, nSockAddrLen); } - // Overridable callbacks protected: - virtual void OnWakeup(); virtual void OnReceive(int nErrorCode); virtual void OnSend(int nErrorCode); virtual void OnOutOfBandData(int nErrorCode); @@ -146,14 +118,24 @@ protected: virtual void OnConnect(int nErrorCode); virtual void OnClose(int nErrorCode); // Implementation - void StartListener(long lEvent); - long m_EventMask; - unsigned long thread_id; - HANDLE h_thread; - WSAEVENT m_hEvent[2]; // socket event for receive and send actions - unsigned int SocketThread(); //Client Thread + int StartListener(); + int StartWriter(); + bool SignalWriter(); + + HANDLE h_reader; + HANDLE h_writer; + unsigned long reader_id; + unsigned long writer_id; + unsigned int SocketReader(); //Receiver Thread + unsigned int SocketWriter(); //Sender Thread + bool listen_mode; + bool connect_pending; + bool send_pending; + HANDLE send_count; + // wrapper for thread routine -static DWORD WINAPI SocketThreadProc( void * pParam ); +static DWORD WINAPI SocketReaderProc( void * pParam ); +static DWORD WINAPI SocketWriterProc( void * pParam ); }; -- cgit v1.1 From 19ce23a32f459a91a76035f2fee5c859066fa5fa Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:05:50 +0000 Subject: Utilisateur : Fcolin Date : 14/09/01 Heure : 16:44 Archivé dans $/Ivy Commentaire: correction BUG Ivy socket Listen apres start Listener et regexp_in.resize (vss 7) --- Ivy/ThreadedSocket.h | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'Ivy/ThreadedSocket.h') diff --git a/Ivy/ThreadedSocket.h b/Ivy/ThreadedSocket.h index ab8e3cd..1827c52 100644 --- a/Ivy/ThreadedSocket.h +++ b/Ivy/ThreadedSocket.h @@ -42,6 +42,7 @@ public: int Connect(const char * lpszHostAddress, unsigned int nHostPort); int Connect(const SOCKADDR* lpSockAddr, int nSockAddrLen); + int Listen(int nConnectionBacklog=5); virtual int Receive(void* lpBuf, int nBufLen, int nFlags = 0); @@ -87,13 +88,7 @@ inline int IOCtl(long lCommand, unsigned long* lpArgument) { return ioctlsocket(m_hSocket, lCommand, lpArgument); } -inline int Listen(int nConnectionBacklog=5) - { - int err = listen(m_hSocket, nConnectionBacklog); - if ( !err ) - listen_mode = true; - return err; - } + inline int ReceiveFrom(void* lpBuf, int nBufLen, SOCKADDR* lpSockAddr, int* lpSockAddrLen, int nFlags = 0) { int lg = recvfrom(m_hSocket, (LPSTR)lpBuf, nBufLen, nFlags, lpSockAddr, lpSockAddrLen); -- cgit v1.1 From fe6c1ec690a82deddc9fa0c5ff9eb5dde9c83c8c Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:05:52 +0000 Subject: Utilisateur : Fcolin Date : 25/10/01 Heure : 18:39 Archivé dans $/Ivy (vss 8) --- Ivy/ThreadedSocket.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'Ivy/ThreadedSocket.h') diff --git a/Ivy/ThreadedSocket.h b/Ivy/ThreadedSocket.h index 1827c52..9771f10 100644 --- a/Ivy/ThreadedSocket.h +++ b/Ivy/ThreadedSocket.h @@ -21,7 +21,7 @@ public: public: SOCKET m_hSocket; - operator SOCKET() const; + inline operator SOCKET() const { return m_hSocket; }; void GetPeerName(string & rPeerAddress, unsigned int& rPeerPort); @@ -57,9 +57,6 @@ public: unsigned int nHostPort, const char * lpszHostAddress = 0, int nFlags = 0); - -inline CThreadedSocket::operator SOCKET() const - { return m_hSocket; } inline int GetPeerName(SOCKADDR* lpSockAddr, int* lpSockAddrLen) { return getpeername(m_hSocket, lpSockAddr, lpSockAddrLen); -- cgit v1.1 From bfcb17aa05cda240abeb0fffc41bb112b04e00eb Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:05:54 +0000 Subject: Utilisateur : Fcolin Date : 2/06/05 Heure : 18:42 Archivé dans $/Bus/Ivy Commentaire: Suppression de la STL et ajout d'un namespace pour les datatypes internes Ivy (vss 9) --- Ivy/ThreadedSocket.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Ivy/ThreadedSocket.h') diff --git a/Ivy/ThreadedSocket.h b/Ivy/ThreadedSocket.h index 9771f10..85262cd 100644 --- a/Ivy/ThreadedSocket.h +++ b/Ivy/ThreadedSocket.h @@ -23,9 +23,9 @@ public: inline operator SOCKET() const { return m_hSocket; }; - void GetPeerName(string & rPeerAddress, unsigned int& rPeerPort); + void GetPeerName(ivy::string & rPeerAddress, unsigned int& rPeerPort); - void GetSockName(string & rSocketAddress, unsigned int& rSocketPort); + void GetSockName(ivy::string & rSocketAddress, unsigned int& rSocketPort); // Operations public: @@ -47,7 +47,7 @@ public: virtual int Receive(void* lpBuf, int nBufLen, int nFlags = 0); int ReceiveFrom(void* lpBuf, int nBufLen, - string & rSocketAddress, unsigned int & rSocketPort, int nFlags = 0); + ivy::string & rSocketAddress, unsigned int & rSocketPort, int nFlags = 0); enum { receives = 0, sends = 1, both = 2 }; -- cgit v1.1 From d335c71e7c5c30293d82d8336494cb629e2d610e Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:05:56 +0000 Subject: Utilisateur : Fcolin Date : 23/09/05 Heure : 15:27 Archivé dans $/Bus/Ivy Commentaire: (vss 10) --- Ivy/ThreadedSocket.h | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'Ivy/ThreadedSocket.h') diff --git a/Ivy/ThreadedSocket.h b/Ivy/ThreadedSocket.h index 85262cd..ad33c3e 100644 --- a/Ivy/ThreadedSocket.h +++ b/Ivy/ThreadedSocket.h @@ -29,11 +29,11 @@ public: // Operations public: - int Socket(int nSocketType=SOCK_STREAM, int nProtocolType = 0, int nAddressFormat = PF_INET); + SOCKET Socket(int nSocketType=SOCK_STREAM, int nProtocolType = 0, int nAddressFormat = PF_INET); int AddMember( const char * lpszHostAddress ); - virtual int Accept(CThreadedSocket& rConnectedSocket, + virtual SOCKET Accept(CThreadedSocket& rConnectedSocket, SOCKADDR* lpSockAddr = NULL, int* lpSockAddrLen = NULL); int Bind(unsigned int nSocketPort, const char * lpszSocketAddress = 0); @@ -44,16 +44,16 @@ public: int Connect(const SOCKADDR* lpSockAddr, int nSockAddrLen); int Listen(int nConnectionBacklog=5); - virtual int Receive(void* lpBuf, int nBufLen, int nFlags = 0); + virtual size_t Receive(void* lpBuf, size_t nBufLen, int nFlags = 0); - int ReceiveFrom(void* lpBuf, int nBufLen, + size_t ReceiveFrom(void* lpBuf, size_t nBufLen, ivy::string & rSocketAddress, unsigned int & rSocketPort, int nFlags = 0); enum { receives = 0, sends = 1, both = 2 }; - virtual int Send(const void* lpBuf, int nBufLen, int nFlags = 0); + virtual size_t Send(const void* lpBuf, size_t nBufLen, int nFlags = 0); - int SendTo(const void* lpBuf, int nBufLen, + size_t SendTo(const void* lpBuf, size_t nBufLen, unsigned int nHostPort, const char * lpszHostAddress = 0, int nFlags = 0); @@ -86,18 +86,20 @@ inline int IOCtl(long lCommand, unsigned long* lpArgument) return ioctlsocket(m_hSocket, lCommand, lpArgument); } -inline int ReceiveFrom(void* lpBuf, int nBufLen, SOCKADDR* lpSockAddr, int* lpSockAddrLen, int nFlags = 0) +inline size_t ReceiveFrom(void* lpBuf, size_t nBufLen, SOCKADDR* lpSockAddr, size_t* lpSockAddrLen, int nFlags = 0) { - int lg = recvfrom(m_hSocket, (LPSTR)lpBuf, nBufLen, nFlags, lpSockAddr, lpSockAddrLen); + int len = (int)*lpSockAddrLen; // Non conforme a Unix + size_t lg = recvfrom(m_hSocket, (LPSTR)lpBuf, (int)nBufLen, nFlags, lpSockAddr, &len); + *lpSockAddrLen = len; return lg; } inline int ShutDown(int nHow = sends) { return shutdown(m_hSocket,nHow); } -inline int SendTo(const void* lpBuf, int nBufLen, const SOCKADDR* lpSockAddr, int nSockAddrLen, int nFlags = 0) +inline size_t SendTo(const void* lpBuf, size_t nBufLen, const SOCKADDR* lpSockAddr, size_t nSockAddrLen, int nFlags = 0) { - return sendto(m_hSocket, (LPSTR)lpBuf, nBufLen, nFlags, lpSockAddr, nSockAddrLen); + return sendto(m_hSocket, (LPSTR)lpBuf, (int)nBufLen, nFlags, lpSockAddr, (int)nSockAddrLen); } -- cgit v1.1