]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/common/sckstrm.cpp
cleanup for 10.5
[wxWidgets.git] / src / common / sckstrm.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/common/sckstrm.cpp
3// Purpose: wxSocket*Stream
4// Author: Guilhem Lavaux
5// Modified by:
6// Created: 17/07/97
7// RCS-ID: $Id$
8// Copyright: (c)
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16 #pragma hdrstop
17#endif
18
19#if wxUSE_SOCKETS && wxUSE_STREAMS
20
21#include "wx/sckstrm.h"
22
23#ifndef WX_PRECOMP
24 #include "wx/stream.h"
25#endif
26
27#include "wx/socket.h"
28
29// ---------------------------------------------------------------------------
30// wxSocketOutputStream
31// ---------------------------------------------------------------------------
32
33wxSocketOutputStream::wxSocketOutputStream(wxSocketBase& s)
34 : m_o_socket(&s)
35{
36}
37
38wxSocketOutputStream::~wxSocketOutputStream()
39{
40}
41
42size_t wxSocketOutputStream::OnSysWrite(const void *buffer, size_t size)
43{
44 const char *buf = (const char *)buffer;
45 size_t count = 0;
46
47 while ( count < size && m_o_socket->WaitForWrite() )
48 {
49 const size_t ret = m_o_socket->Write(buf, size - count).LastCount();
50
51 buf += ret;
52 count += ret;
53
54 if ( m_o_socket->Error() )
55 {
56 if (m_o_socket->LastError() != wxSOCKET_WOULDBLOCK)
57 {
58 m_lasterror = wxSTREAM_WRITE_ERROR;
59 return count;
60 }
61 }
62 }
63
64 m_lasterror = wxSTREAM_NO_ERROR;
65 return count;
66}
67
68// ---------------------------------------------------------------------------
69// wxSocketInputStream
70// ---------------------------------------------------------------------------
71
72wxSocketInputStream::wxSocketInputStream(wxSocketBase& s)
73 : m_i_socket(&s)
74{
75}
76
77wxSocketInputStream::~wxSocketInputStream()
78{
79}
80
81size_t wxSocketInputStream::OnSysRead(void *buffer, size_t size)
82{
83 char *buf = (char *)buffer;
84 size_t count = 0;
85
86 while ( count < size && m_i_socket->WaitForRead() )
87 {
88 const size_t ret = m_i_socket->Read(buf, size - count).LastCount();
89
90 buf += ret;
91 count += ret;
92
93 if ( m_i_socket->Error() )
94 {
95 if (m_i_socket->LastError() != wxSOCKET_WOULDBLOCK)
96 {
97 m_lasterror = wxSTREAM_READ_ERROR;
98 return count;
99 }
100 }
101 }
102
103 m_lasterror = wxSTREAM_NO_ERROR;
104 return count;
105}
106
107// ---------------------------------------------------------------------------
108// wxSocketStream
109// ---------------------------------------------------------------------------
110
111wxSocketStream::wxSocketStream(wxSocketBase& s)
112 : wxSocketInputStream(s), wxSocketOutputStream(s)
113{
114}
115
116wxSocketStream::~wxSocketStream()
117{
118}
119
120#endif
121 // wxUSE_STREAMS && wxUSE_SOCKETS