]>
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"
27 #include "wx/protocol/protocol.h"
30 /////////////////////////////////////////////////////////////////
32 /////////////////////////////////////////////////////////////////
35 * --------------------------------------------------------------
36 * --------- wxProtoInfo CONSTRUCTOR ----------------------------
37 * --------------------------------------------------------------
40 wxProtoInfo::wxProtoInfo(const char *name
, const char *serv
,
41 const bool need_host1
, wxClassInfo
*info
)
46 m_needhost
= need_host1
;
47 next
= wxURL::g_protocols
;
48 wxURL::g_protocols
= this;
51 /////////////////////////////////////////////////////////////////
52 // wxProtocol ///////////////////////////////////////////////////
53 /////////////////////////////////////////////////////////////////
55 IMPLEMENT_ABSTRACT_CLASS(wxProtocol
, wxSocketClient
)
57 wxProtocol::wxProtocol()
62 bool wxProtocol::Reconnect()
77 wxProtocolError
GetLine(wxSocketBase
*sock
, wxString
& result
) {
78 #define PROTO_BSIZE 2048
80 char tmp_buf
[PROTO_BSIZE
], tmp_str
[PROTO_BSIZE
];
84 avail
= sock
->Read(tmp_buf
, PROTO_BSIZE
).LastCount();
85 if (sock
->LastError() != 0 || avail
== 0)
86 return wxPROTO_NETERR
;
88 memcpy(tmp_str
, tmp_buf
, avail
);
90 // Not implemented on all systems
91 // ret = (char *)memccpy(tmp_str, tmp_buf, '\n', avail);
93 for (ret
=tmp_str
;ret
< (tmp_str
+avail
); ret
++)
100 return wxPROTO_PROTERR
;
104 result
= result
.Left(result
.Length()-1);
106 size
= ret
-tmp_str
+1;
107 sock
->CreatePushbackBefore(&tmp_buf
[size
], avail
-size
);
108 return wxPROTO_NOERR
;