]> git.saurik.com Git - wxWidgets.git/blame - src/common/sckstrm.cpp
Updated list of subprojects.
[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{
2f0add5a
VZ
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;
375abe3d
GL
66}
67
f4ada568
GL
68// ---------------------------------------------------------------------------
69// wxSocketInputStream
70// ---------------------------------------------------------------------------
71
72wxSocketInputStream::wxSocketInputStream(wxSocketBase& s)
73 : m_i_socket(&s)
74{
75}
76
77wxSocketInputStream::~wxSocketInputStream()
78{
79}
80
375abe3d
GL
81size_t wxSocketInputStream::OnSysRead(void *buffer, size_t size)
82{
2f0add5a
VZ
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;
375abe3d
GL
105}
106
f4ada568 107// ---------------------------------------------------------------------------
75ed1d15 108// wxSocketStream
f4ada568 109// ---------------------------------------------------------------------------
f4ada568
GL
110
111wxSocketStream::wxSocketStream(wxSocketBase& s)
112 : wxSocketInputStream(s), wxSocketOutputStream(s)
113{
114}
75ed1d15
GL
115
116wxSocketStream::~wxSocketStream()
117{
118}
35a4dab7
GL
119
120#endif
ce4169a4 121 // wxUSE_STREAMS && wxUSE_SOCKETS