aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-07-25 17:25:28 +0000
committerMike Buland <eichlan@xagasoft.com>2011-07-25 17:25:28 +0000
commitd3a6d910f96d1509b17165b635663b608681b89a (patch)
tree923b1e0f783d5b710f82664591812895cb9dbba3 /src
parentd0d86b9ae6a86fec59f69c76352c640e759bd4a1 (diff)
downloadlibbu++-d3a6d910f96d1509b17165b635663b608681b89a.tar.gz
libbu++-d3a6d910f96d1509b17165b635663b608681b89a.tar.bz2
libbu++-d3a6d910f96d1509b17165b635663b608681b89a.tar.xz
libbu++-d3a6d910f96d1509b17165b635663b608681b89a.zip
In theory, after constructing a TcpSocket object, you can now take the
operating system socket handle away and use it yourself, after doing so, the TcpSocket will not close the socket when it exits, or be able to effect it ever again.
Diffstat (limited to '')
-rw-r--r--src/tcpsocket.cpp17
-rw-r--r--src/tcpsocket.h20
2 files changed, 28 insertions, 9 deletions
diff --git a/src/tcpsocket.cpp b/src/tcpsocket.cpp
index 399ec44..b9b215c 100644
--- a/src/tcpsocket.cpp
+++ b/src/tcpsocket.cpp
@@ -31,7 +31,7 @@
31 31
32namespace Bu { subExceptionDef( TcpSocketException ) } 32namespace Bu { subExceptionDef( TcpSocketException ) }
33 33
34Bu::TcpSocket::TcpSocket( int nTcpSocket ) : 34Bu::TcpSocket::TcpSocket( handle nTcpSocket ) :
35 nTcpSocket( nTcpSocket ), 35 nTcpSocket( nTcpSocket ),
36 bActive( true ), 36 bActive( true ),
37 bBlocking( true ) 37 bBlocking( true )
@@ -443,11 +443,24 @@ Bu::String Bu::TcpSocket::getAddress() const
443 return sAddress; 443 return sAddress;
444} 444}
445 445
446Bu::TcpSocket::operator int() const 446Bu::TcpSocket::operator Bu::TcpSocket::handle() const
447{ 447{
448 return nTcpSocket; 448 return nTcpSocket;
449} 449}
450 450
451Bu::TcpSocket::handle Bu::TcpSocket::getHandle() const
452{
453 return nTcpSocket;
454}
455
456Bu::TcpSocket::handle Bu::TcpSocket::takeHandle()
457{
458 handle nRet = nTcpSocket;
459 bActive = false;
460 nTcpSocket = 0;
461 return nRet;
462}
463
451Bu::size Bu::TcpSocket::getSize() const 464Bu::size Bu::TcpSocket::getSize() const
452{ 465{
453 throw UnsupportedException(); 466 throw UnsupportedException();
diff --git a/src/tcpsocket.h b/src/tcpsocket.h
index dbaaa5e..52218bd 100644
--- a/src/tcpsocket.h
+++ b/src/tcpsocket.h
@@ -60,7 +60,13 @@ namespace Bu
60 class TcpSocket : public Stream 60 class TcpSocket : public Stream
61 { 61 {
62 public: 62 public:
63 TcpSocket( int nTcpSocket ); 63#ifdef WIN32
64 typedef unsigned int handle;
65#else
66 typedef int handle;
67#endif
68
69 TcpSocket( handle nTcpSocket );
64 TcpSocket( const String &sAddr, int nPort, int nTimeout=30, 70 TcpSocket( const String &sAddr, int nPort, int nTimeout=30,
65 bool bBlocking=true ); 71 bool bBlocking=true );
66 virtual ~TcpSocket(); 72 virtual ~TcpSocket();
@@ -96,7 +102,10 @@ namespace Bu
96 virtual void setSize( size iSize ); 102 virtual void setSize( size iSize );
97 103
98 Bu::String getAddress() const; 104 Bu::String getAddress() const;
99 operator int() const; 105 operator handle() const;
106
107 handle getHandle() const;
108 handle takeHandle();
100 109
101 virtual size getSize() const; 110 virtual size getSize() const;
102 virtual size getBlockSize() const; 111 virtual size getBlockSize() const;
@@ -105,11 +114,8 @@ namespace Bu
105 private: 114 private:
106 void setAddress(); 115 void setAddress();
107 116
108#ifdef WIN32 117 handle nTcpSocket;
109 unsigned int nTcpSocket; 118
110#else
111 int nTcpSocket;
112#endif
113 bool bActive; 119 bool bActive;
114 bool bBlocking; 120 bool bBlocking;
115 String sReadBuf; 121 String sReadBuf;