* wxSocket fixes: FTP, HTTP works really now. GTK fixes to prevent infinite loop.

* wxSocket stream fix: they can be encapsulated by now
* Doc update: wxURL::GetPath


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1818 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Guilhem Lavaux
1999-02-27 21:01:05 +00:00
parent 839b865d08
commit 375abe3dac
9 changed files with 66 additions and 8 deletions

View File

@@ -62,6 +62,15 @@ Returns the name of the protocol which will be used to get the URL.
Returns a reference to the protocol which will be used to get the URL.
%
% GetPath
%
\membersection{wxURL::GetPath}
\func{wxString}{GetPath}{\void}
Returns the path of the file to fetch. This path was encoded in the URL.
%
% GetError
%

View File

@@ -32,6 +32,8 @@ class WXDLLEXPORT wxSocketOutputStream : public wxOutputStream
protected:
wxSocketBase *m_o_socket;
size_t OnSysWrite(const void *buffer, size_t bufsize);
};
class WXDLLEXPORT wxSocketInputStream : public wxInputStream
@@ -48,6 +50,8 @@ class WXDLLEXPORT wxSocketInputStream : public wxInputStream
protected:
wxSocketBase *m_i_socket;
size_t OnSysRead(void *buffer, size_t bufsize);
};
class WXDLLEXPORT wxSocketStream : public wxSocketInputStream,

View File

@@ -81,7 +81,10 @@ class WXDLLEXPORT wxSocketBase : public wxEvtHandler
{
DECLARE_CLASS(wxSocketBase)
#ifdef __WXMAC__
friend void wxMacSocketOnRequestProc(void *refcon , short event) ;
friend void wxMacSocketOnRequestProc(void *refcon , short event) ;
#endif
#if defined(__WXGTK__) && defined(WXSOCK_INTERNAL)
friend void wxPrereadSocket(wxSocketBase *sock);
#endif
public:

View File

@@ -62,6 +62,7 @@ public:
{ return m_protoinfo->m_protoname; }
inline wxProtocol& GetProtocol() { return *m_protocol; }
inline wxURLError GetError() const { return m_error; }
inline wxString GetPath() const { return m_path; }
wxInputStream *GetInputStream();

View File

@@ -235,7 +235,7 @@ void MyFrame::OnExecTest1(wxCommandEvent& WXUNUSED(evt))
wxYield();
/* Init */
buf = copystring("Salut ! Salut ! Salut ! Salut Toto\n");
buf = copystring("Hi ! Hi ! Hi !\n");
buf2 = new char[strlen(buf)+1];
char c = 0xbe;
sock->WriteMsg(&c, 1);

View File

@@ -253,7 +253,7 @@ public:
wxInputFTPStream(wxFTP *ftp_clt, wxSocketBase *sock)
: wxSocketInputStream(*sock), m_ftp(ftp_clt) {}
size_t StreamSize() { return m_ftpsize; }
size_t StreamSize() const { return m_ftpsize; }
virtual ~wxInputFTPStream(void)
{
if (LastError() != wxStream_NOERROR)
@@ -351,7 +351,7 @@ wxInputStream *wxFTP::GetInputStream(const wxString& path)
pos_size = m_lastResult.Index('(');
if (pos_size != wxNOT_FOUND) {
wxString str_size = m_lastResult(pos_size, m_lastResult.Index(')'));
wxString str_size = m_lastResult(pos_size+1, m_lastResult.Index(')')-1);
in_stream->m_ftpsize = atoi(WXSTRINGCAST str_size);
}
@@ -401,5 +401,9 @@ wxList *wxFTP::GetList(const wxString& wildcard)
return NULL;
}
sock->SetEventHandler(*GetNextHandler(), m_id);
sock->Notify(m_notifyme);
sock->SetNotify(m_neededreq);
return file_list;
}

View File

@@ -45,6 +45,11 @@ wxOutputStream& wxSocketOutputStream::Write(const void *buffer, size_t size)
return *this;
}
size_t wxSocketOutputStream::OnSysWrite(const void *buffer, size_t size)
{
return m_o_socket->Write((const char *)buffer, size).LastCount();
}
// ---------------------------------------------------------------------------
// wxSocketInputStream
// ---------------------------------------------------------------------------
@@ -64,6 +69,11 @@ wxInputStream& wxSocketInputStream::Read(void *buffer, size_t size)
return *this;
}
size_t wxSocketInputStream::OnSysRead(void *buffer, size_t size)
{
return m_i_socket->Read((char *)buffer, size).LastCount();
}
// ---------------------------------------------------------------------------
// wxSocketStream
// ---------------------------------------------------------------------------

View File

@@ -363,8 +363,10 @@ wxSocketBase& wxSocketBase::Read(char* buffer, size_t nbytes)
// If we have got the whole needed buffer or if we don't want to
// wait then it returns immediately.
if (!nbytes || (m_lcount && !(m_flags & WAITALL)) )
if (!nbytes || (count && !(m_flags & WAITALL)) ) {
m_lcount = count;
return *this;
}
m_lcount = 0;
WantBuffer(buffer, nbytes, EVT_READ);
@@ -681,6 +683,20 @@ bool wxSocketBase::WaitForLost(long seconds, long microseconds)
// --------- wxSocketBase callback management -------------------
// --------------------------------------------------------------
#ifdef __WXGTK__
void wxPrereadSocket(wxSocketBase *sock)
{
char tmp_buf[1024];
int got = 0;
do {
got = recv(sock->m_fd, tmp_buf, 1024, 0);
if (got > 0)
sock->CreatePushbackAfter(tmp_buf, got);
} while (got > 0);
}
#endif
#if defined(__WXMOTIF__) || defined(__WXXT__) || defined(__WXGTK__)
#if defined(__WXMOTIF__) || defined(__WXXT__)
static void wx_socket_read(XtPointer client, int *fid,
@@ -708,6 +724,15 @@ static void wx_socket_read(gpointer client, gint fd,
{
if (!(sock->NeededReq() & wxSocketBase::REQ_READ))
{
#ifdef __WXGTK__
// We can't exit from the GDK main loop because it doesn't accept
// destroying input event while we are in a event dispatch.
// So we will preread socket and we put the data in the pushback.
wxPrereadSocket(sock);
// Then we set the socket as BLOCKING
int flag = 0;
ioctl(fd, FIONBIO, &flag);
#endif
return;
}
@@ -1119,7 +1144,10 @@ void wxSocketBase::CreatePushbackAfter(const char *buffer, size_t size)
{
char *curr_pos;
m_unread = (char *) realloc(m_unread, m_unrd_size+size);
if (m_unread != NULL)
m_unread = (char *) realloc(m_unread, m_unrd_size+size);
else
m_unread = (char *) malloc(size);
curr_pos = m_unread + m_unrd_size;
memcpy(curr_pos, buffer, size);

View File

@@ -160,10 +160,9 @@ bool wxURL::PrepHost(wxString& url)
// Retrieve service number
pos2 = temp_url.Find(':', TRUE);
if (pos2 != -1 && pos2 < pos) {
m_servname = url(pos2, pos);
m_servname = temp_url(pos2+1, pos);
if (!m_servname.IsNumber())
return FALSE;
pos2 = pos;
temp_url = temp_url(0, pos2);
}