]>
git.saurik.com Git - wxWidgets.git/blob - src/common/sckstrm.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/sckstrm.cpp
3 // Purpose: wxSocket*Stream
4 // Author: Guilhem Lavaux
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
19 #if wxUSE_SOCKETS && wxUSE_STREAMS
21 #include "wx/sckstrm.h"
24 #include "wx/stream.h"
27 #include "wx/socket.h"
29 // ---------------------------------------------------------------------------
30 // wxSocketOutputStream
31 // ---------------------------------------------------------------------------
33 wxSocketOutputStream::wxSocketOutputStream(wxSocketBase
& s
)
38 wxSocketOutputStream::~wxSocketOutputStream()
42 size_t wxSocketOutputStream::OnSysWrite(const void *buffer
, size_t size
)
44 const char *buf
= (const char *)buffer
;
47 while ( count
< size
&& m_o_socket
->WaitForWrite() )
49 const size_t ret
= m_o_socket
->Write(buf
, size
- count
).LastCount();
54 if ( m_o_socket
->Error() )
56 if (m_o_socket
->LastError() != wxSOCKET_WOULDBLOCK
)
58 m_lasterror
= wxSTREAM_WRITE_ERROR
;
64 m_lasterror
= wxSTREAM_NO_ERROR
;
68 // ---------------------------------------------------------------------------
69 // wxSocketInputStream
70 // ---------------------------------------------------------------------------
72 wxSocketInputStream::wxSocketInputStream(wxSocketBase
& s
)
77 wxSocketInputStream::~wxSocketInputStream()
81 size_t wxSocketInputStream::OnSysRead(void *buffer
, size_t size
)
83 char *buf
= (char *)buffer
;
86 while ( count
< size
&& m_i_socket
->WaitForRead() )
88 const size_t ret
= m_i_socket
->Read(buf
, size
- count
).LastCount();
93 if ( m_i_socket
->Error() )
95 if (m_i_socket
->LastError() != wxSOCKET_WOULDBLOCK
)
97 m_lasterror
= wxSTREAM_READ_ERROR
;
103 m_lasterror
= wxSTREAM_NO_ERROR
;
107 // ---------------------------------------------------------------------------
109 // ---------------------------------------------------------------------------
111 wxSocketStream::wxSocketStream(wxSocketBase
& s
)
112 : wxSocketInputStream(s
), wxSocketOutputStream(s
)
116 wxSocketStream::~wxSocketStream()
121 // wxUSE_STREAMS && wxUSE_SOCKETS