]>
git.saurik.com Git - wxWidgets.git/blob - src/common/protocol.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Implement protocol base class
4 // Author: Guilhem Lavaux
8 // Copyright: (c) 1997, 1998 Guilhem Lavaux
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "protocol.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
25 #include "wx/protocol/protocol.h"
27 #include "wx/module.h"
31 /////////////////////////////////////////////////////////////////
33 /////////////////////////////////////////////////////////////////
36 * --------------------------------------------------------------
37 * --------- wxProtoInfo CONSTRUCTOR ----------------------------
38 * --------------------------------------------------------------
41 wxProtoInfo::wxProtoInfo(const wxChar
*name
, const wxChar
*serv
,
42 const bool need_host1
, wxClassInfo
*info
)
47 m_needhost
= need_host1
;
48 next
= wxURL::ms_protocols
;
49 wxURL::ms_protocols
= this;
52 /////////////////////////////////////////////////////////////////
53 // wxProtocol ///////////////////////////////////////////////////
54 /////////////////////////////////////////////////////////////////
57 IMPLEMENT_ABSTRACT_CLASS(wxProtocol
, wxSocketClient
)
59 IMPLEMENT_ABSTRACT_CLASS(wxProtocol
, wxObject
)
62 wxProtocol::wxProtocol()
69 bool wxProtocol::Reconnect()
86 // ----------------------------------------------------------------------------
87 // Read a line from socket
88 // ----------------------------------------------------------------------------
90 // TODO ReadLine() should use buffers private to wxProtocol for efficiency!
93 wxProtocolError
wxProtocol::ReadLine(wxSocketBase
*socket
, wxString
& result
)
96 char ch
, chLast
= '\0';
97 while ( !socket
->Read(&ch
, sizeof(ch
)).Error() )
102 // remember it, if the following is '\n', we're done
107 // only ends line if the previous character was '\r'
108 if ( chLast
== '\r' )
111 return wxPROTO_NOERR
;
127 return wxPROTO_NETERR
;
130 wxProtocolError
wxProtocol::ReadLine(wxString
& result
)
132 return ReadLine(this, result
);
135 // old function which only chops '\n' and not '\r\n'
136 wxProtocolError
GetLine(wxSocketBase
*sock
, wxString
& result
) {
137 #define PROTO_BSIZE 2048
139 char tmp_buf
[PROTO_BSIZE
], tmp_str
[PROTO_BSIZE
];
143 avail
= sock
->Read(tmp_buf
, PROTO_BSIZE
).LastCount();
144 if (sock
->Error() || avail
== 0)
145 return wxPROTO_NETERR
;
147 memcpy(tmp_str
, tmp_buf
, avail
);
149 // Not implemented on all systems
150 // ret = (char *)memccpy(tmp_str, tmp_buf, '\n', avail);
152 for (ret
=tmp_str
;ret
< (tmp_str
+avail
); ret
++)
159 return wxPROTO_PROTERR
;
163 result
= result
.Left(result
.Length()-1);
165 size
= ret
-tmp_str
+1;
166 sock
->Unread(&tmp_buf
[size
], avail
-size
);
167 return wxPROTO_NOERR
;
171 #endif // wxUSE_PROTOCOL