]>
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"
17 #include <wx/wxprec.h>
22 #include "wx/protocol/protocol.h"
29 /////////////////////////////////////////////////////////////////
31 /////////////////////////////////////////////////////////////////
34 * --------------------------------------------------------------
35 * --------- wxProtoInfo CONSTRUCTOR ----------------------------
36 * --------------------------------------------------------------
39 wxProtoInfo::wxProtoInfo(const char *name
, const char *serv
,
40 const bool need_host1
, wxClassInfo
*info
)
45 m_needhost
= need_host1
;
46 next
= wxURL::g_protocols
;
47 wxURL::g_protocols
= this;
50 /////////////////////////////////////////////////////////////////
51 // wxProtocol ///////////////////////////////////////////////////
52 /////////////////////////////////////////////////////////////////
54 IMPLEMENT_ABSTRACT_CLASS(wxProtocol
, wxSocketClient
)
56 wxProtocol::wxProtocol()
61 bool wxProtocol::Reconnect()
76 wxProtocolError
GetLine(wxSocketBase
*sock
, wxString
& result
) {
77 #define PROTO_BSIZE 2048
79 char tmp_buf
[PROTO_BSIZE
], tmp_str
[PROTO_BSIZE
];
83 avail
= sock
->Read(tmp_buf
, PROTO_BSIZE
).LastCount();
84 if (sock
->LastError() != 0 || avail
== 0)
85 return wxPROTO_NETERR
;
87 memcpy(tmp_str
, tmp_buf
, avail
);
89 // Not implemented on all systems
90 // ret = (char *)memccpy(tmp_str, tmp_buf, '\n', avail);
92 for (ret
=tmp_str
;ret
< (tmp_str
+avail
); ret
++)
99 return wxPROTO_PROTERR
;
103 result
= result
.Left(result
.Length()-1);
105 size
= ret
-tmp_str
+1;
106 sock
->CreatePushbackBefore(&tmp_buf
[size
], avail
-size
);
107 return wxPROTO_NOERR
;