]>
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 size_t ret
= m_o_socket
->Write((const char *)buffer
, size
).LastCount();
45 m_lasterror
= m_o_socket
->Error() ? wxSTREAM_WRITE_ERROR
: wxSTREAM_NO_ERROR
;
48 // Patch 1476893 caused Advise to hang, needs further investigation
50 const char *buf
= (const char *)buffer
;
53 while ( count
< size
&& m_o_socket
->WaitForWrite() )
55 const size_t ret
= m_o_socket
->Write(buf
, size
- count
).LastCount();
60 if ( m_o_socket
->Error() )
62 if (m_o_socket
->LastError() != wxSOCKET_WOULDBLOCK
)
64 m_lasterror
= wxSTREAM_WRITE_ERROR
;
70 m_lasterror
= wxSTREAM_NO_ERROR
;
75 // ---------------------------------------------------------------------------
76 // wxSocketInputStream
77 // ---------------------------------------------------------------------------
79 wxSocketInputStream::wxSocketInputStream(wxSocketBase
& s
)
84 wxSocketInputStream::~wxSocketInputStream()
88 size_t wxSocketInputStream::OnSysRead(void *buffer
, size_t size
)
90 size_t ret
= m_i_socket
->Read((char *)buffer
, size
).LastCount();
91 m_lasterror
= m_i_socket
->Error() ? wxSTREAM_READ_ERROR
: wxSTREAM_NO_ERROR
;
94 // Patch 1476893 caused Advise to hang, needs further investigation
96 char *buf
= (char *)buffer
;
99 while ( count
< size
&& m_i_socket
->WaitForRead() )
101 const size_t ret
= m_i_socket
->Read(buf
, size
- count
).LastCount();
106 if ( m_i_socket
->Error() )
108 if (m_i_socket
->LastError() != wxSOCKET_WOULDBLOCK
)
110 m_lasterror
= wxSTREAM_READ_ERROR
;
116 m_lasterror
= wxSTREAM_NO_ERROR
;
121 // ---------------------------------------------------------------------------
123 // ---------------------------------------------------------------------------
125 wxSocketStream::wxSocketStream(wxSocketBase
& s
)
126 : wxSocketInputStream(s
), wxSocketOutputStream(s
)
130 wxSocketStream::~wxSocketStream()
135 // wxUSE_STREAMS && wxUSE_SOCKETS