]> git.saurik.com Git - wxWidgets.git/blame - src/common/sckstrm.cpp
fix compilation when one of wxUSE_LISTCTRL and wxUSE_TREECTRL is defined but the...
[wxWidgets.git] / src / common / sckstrm.cpp
CommitLineData
f4ada568 1/////////////////////////////////////////////////////////////////////////////
8898456d 2// Name: src/common/sckstrm.cpp
f4ada568
GL
3// Purpose: wxSocket*Stream
4// Author: Guilhem Lavaux
5// Modified by:
6// Created: 17/07/97
7// RCS-ID: $Id$
8// Copyright: (c)
65571936 9// Licence: wxWindows licence
f4ada568 10/////////////////////////////////////////////////////////////////////////////
f4ada568 11
fcc6dddd
JS
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
8898456d 16 #pragma hdrstop
fcc6dddd
JS
17#endif
18
8898456d
WS
19#if wxUSE_SOCKETS && wxUSE_STREAMS
20
530ecef0
WS
21#include "wx/sckstrm.h"
22
fcc6dddd 23#ifndef WX_PRECOMP
530ecef0 24 #include "wx/stream.h"
fcc6dddd
JS
25#endif
26
f4ada568 27#include "wx/socket.h"
f4ada568
GL
28
29// ---------------------------------------------------------------------------
30// wxSocketOutputStream
31// ---------------------------------------------------------------------------
32
33wxSocketOutputStream::wxSocketOutputStream(wxSocketBase& s)
34 : m_o_socket(&s)
35{
36}
37
38wxSocketOutputStream::~wxSocketOutputStream()
39{
40}
41
375abe3d
GL
42size_t wxSocketOutputStream::OnSysWrite(const void *buffer, size_t size)
43{
7e134dc1
JS
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;
46 return ret;
47
48 // Patch 1476893 caused Advise to hang, needs further investigation
49#if 0
2f0add5a
VZ
50 const char *buf = (const char *)buffer;
51 size_t count = 0;
52
53 while ( count < size && m_o_socket->WaitForWrite() )
54 {
55 const size_t ret = m_o_socket->Write(buf, size - count).LastCount();
56
57 buf += ret;
58 count += ret;
59
60 if ( m_o_socket->Error() )
61 {
62 if (m_o_socket->LastError() != wxSOCKET_WOULDBLOCK)
63 {
64 m_lasterror = wxSTREAM_WRITE_ERROR;
65 return count;
66 }
67 }
68 }
69
70 m_lasterror = wxSTREAM_NO_ERROR;
71 return count;
7e134dc1 72#endif
375abe3d
GL
73}
74
f4ada568
GL
75// ---------------------------------------------------------------------------
76// wxSocketInputStream
77// ---------------------------------------------------------------------------
78
79wxSocketInputStream::wxSocketInputStream(wxSocketBase& s)
80 : m_i_socket(&s)
81{
82}
83
84wxSocketInputStream::~wxSocketInputStream()
85{
86}
87
375abe3d
GL
88size_t wxSocketInputStream::OnSysRead(void *buffer, size_t size)
89{
7e134dc1
JS
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;
92 return ret;
93
94 // Patch 1476893 caused Advise to hang, needs further investigation
95#if 0
2f0add5a
VZ
96 char *buf = (char *)buffer;
97 size_t count = 0;
98
99 while ( count < size && m_i_socket->WaitForRead() )
100 {
101 const size_t ret = m_i_socket->Read(buf, size - count).LastCount();
102
103 buf += ret;
104 count += ret;
105
106 if ( m_i_socket->Error() )
107 {
108 if (m_i_socket->LastError() != wxSOCKET_WOULDBLOCK)
109 {
110 m_lasterror = wxSTREAM_READ_ERROR;
111 return count;
112 }
113 }
114 }
115
116 m_lasterror = wxSTREAM_NO_ERROR;
117 return count;
7e134dc1 118#endif
375abe3d
GL
119}
120
f4ada568 121// ---------------------------------------------------------------------------
75ed1d15 122// wxSocketStream
f4ada568 123// ---------------------------------------------------------------------------
f4ada568
GL
124
125wxSocketStream::wxSocketStream(wxSocketBase& s)
126 : wxSocketInputStream(s), wxSocketOutputStream(s)
127{
128}
75ed1d15
GL
129
130wxSocketStream::~wxSocketStream()
131{
132}
35a4dab7
GL
133
134#endif
ce4169a4 135 // wxUSE_STREAMS && wxUSE_SOCKETS