* 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:
@@ -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.
|
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
|
% GetError
|
||||||
%
|
%
|
||||||
|
@@ -32,6 +32,8 @@ class WXDLLEXPORT wxSocketOutputStream : public wxOutputStream
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
wxSocketBase *m_o_socket;
|
wxSocketBase *m_o_socket;
|
||||||
|
|
||||||
|
size_t OnSysWrite(const void *buffer, size_t bufsize);
|
||||||
};
|
};
|
||||||
|
|
||||||
class WXDLLEXPORT wxSocketInputStream : public wxInputStream
|
class WXDLLEXPORT wxSocketInputStream : public wxInputStream
|
||||||
@@ -48,6 +50,8 @@ class WXDLLEXPORT wxSocketInputStream : public wxInputStream
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
wxSocketBase *m_i_socket;
|
wxSocketBase *m_i_socket;
|
||||||
|
|
||||||
|
size_t OnSysRead(void *buffer, size_t bufsize);
|
||||||
};
|
};
|
||||||
|
|
||||||
class WXDLLEXPORT wxSocketStream : public wxSocketInputStream,
|
class WXDLLEXPORT wxSocketStream : public wxSocketInputStream,
|
||||||
|
@@ -83,6 +83,9 @@ class WXDLLEXPORT wxSocketBase : public wxEvtHandler
|
|||||||
#ifdef __WXMAC__
|
#ifdef __WXMAC__
|
||||||
friend void wxMacSocketOnRequestProc(void *refcon , short event) ;
|
friend void wxMacSocketOnRequestProc(void *refcon , short event) ;
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(__WXGTK__) && defined(WXSOCK_INTERNAL)
|
||||||
|
friend void wxPrereadSocket(wxSocketBase *sock);
|
||||||
|
#endif
|
||||||
public:
|
public:
|
||||||
|
|
||||||
enum wxSockFlags { NONE=0, NOWAIT=1, WAITALL=2, SPEED=4 };
|
enum wxSockFlags { NONE=0, NOWAIT=1, WAITALL=2, SPEED=4 };
|
||||||
|
@@ -62,6 +62,7 @@ public:
|
|||||||
{ return m_protoinfo->m_protoname; }
|
{ return m_protoinfo->m_protoname; }
|
||||||
inline wxProtocol& GetProtocol() { return *m_protocol; }
|
inline wxProtocol& GetProtocol() { return *m_protocol; }
|
||||||
inline wxURLError GetError() const { return m_error; }
|
inline wxURLError GetError() const { return m_error; }
|
||||||
|
inline wxString GetPath() const { return m_path; }
|
||||||
|
|
||||||
wxInputStream *GetInputStream();
|
wxInputStream *GetInputStream();
|
||||||
|
|
||||||
|
@@ -235,7 +235,7 @@ void MyFrame::OnExecTest1(wxCommandEvent& WXUNUSED(evt))
|
|||||||
wxYield();
|
wxYield();
|
||||||
|
|
||||||
/* Init */
|
/* Init */
|
||||||
buf = copystring("Salut ! Salut ! Salut ! Salut Toto\n");
|
buf = copystring("Hi ! Hi ! Hi !\n");
|
||||||
buf2 = new char[strlen(buf)+1];
|
buf2 = new char[strlen(buf)+1];
|
||||||
char c = 0xbe;
|
char c = 0xbe;
|
||||||
sock->WriteMsg(&c, 1);
|
sock->WriteMsg(&c, 1);
|
||||||
|
@@ -253,7 +253,7 @@ public:
|
|||||||
|
|
||||||
wxInputFTPStream(wxFTP *ftp_clt, wxSocketBase *sock)
|
wxInputFTPStream(wxFTP *ftp_clt, wxSocketBase *sock)
|
||||||
: wxSocketInputStream(*sock), m_ftp(ftp_clt) {}
|
: wxSocketInputStream(*sock), m_ftp(ftp_clt) {}
|
||||||
size_t StreamSize() { return m_ftpsize; }
|
size_t StreamSize() const { return m_ftpsize; }
|
||||||
virtual ~wxInputFTPStream(void)
|
virtual ~wxInputFTPStream(void)
|
||||||
{
|
{
|
||||||
if (LastError() != wxStream_NOERROR)
|
if (LastError() != wxStream_NOERROR)
|
||||||
@@ -351,7 +351,7 @@ wxInputStream *wxFTP::GetInputStream(const wxString& path)
|
|||||||
|
|
||||||
pos_size = m_lastResult.Index('(');
|
pos_size = m_lastResult.Index('(');
|
||||||
if (pos_size != wxNOT_FOUND) {
|
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);
|
in_stream->m_ftpsize = atoi(WXSTRINGCAST str_size);
|
||||||
}
|
}
|
||||||
@@ -401,5 +401,9 @@ wxList *wxFTP::GetList(const wxString& wildcard)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sock->SetEventHandler(*GetNextHandler(), m_id);
|
||||||
|
sock->Notify(m_notifyme);
|
||||||
|
sock->SetNotify(m_neededreq);
|
||||||
|
|
||||||
return file_list;
|
return file_list;
|
||||||
}
|
}
|
||||||
|
@@ -45,6 +45,11 @@ wxOutputStream& wxSocketOutputStream::Write(const void *buffer, size_t size)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t wxSocketOutputStream::OnSysWrite(const void *buffer, size_t size)
|
||||||
|
{
|
||||||
|
return m_o_socket->Write((const char *)buffer, size).LastCount();
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// wxSocketInputStream
|
// wxSocketInputStream
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -64,6 +69,11 @@ wxInputStream& wxSocketInputStream::Read(void *buffer, size_t size)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t wxSocketInputStream::OnSysRead(void *buffer, size_t size)
|
||||||
|
{
|
||||||
|
return m_i_socket->Read((char *)buffer, size).LastCount();
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// wxSocketStream
|
// wxSocketStream
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
@@ -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
|
// If we have got the whole needed buffer or if we don't want to
|
||||||
// wait then it returns immediately.
|
// wait then it returns immediately.
|
||||||
if (!nbytes || (m_lcount && !(m_flags & WAITALL)) )
|
if (!nbytes || (count && !(m_flags & WAITALL)) ) {
|
||||||
|
m_lcount = count;
|
||||||
return *this;
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
m_lcount = 0;
|
m_lcount = 0;
|
||||||
WantBuffer(buffer, nbytes, EVT_READ);
|
WantBuffer(buffer, nbytes, EVT_READ);
|
||||||
@@ -681,6 +683,20 @@ bool wxSocketBase::WaitForLost(long seconds, long microseconds)
|
|||||||
// --------- wxSocketBase callback management -------------------
|
// --------- 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__) || defined(__WXGTK__)
|
||||||
#if defined(__WXMOTIF__) || defined(__WXXT__)
|
#if defined(__WXMOTIF__) || defined(__WXXT__)
|
||||||
static void wx_socket_read(XtPointer client, int *fid,
|
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))
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1119,7 +1144,10 @@ void wxSocketBase::CreatePushbackAfter(const char *buffer, size_t size)
|
|||||||
{
|
{
|
||||||
char *curr_pos;
|
char *curr_pos;
|
||||||
|
|
||||||
|
if (m_unread != NULL)
|
||||||
m_unread = (char *) realloc(m_unread, m_unrd_size+size);
|
m_unread = (char *) realloc(m_unread, m_unrd_size+size);
|
||||||
|
else
|
||||||
|
m_unread = (char *) malloc(size);
|
||||||
curr_pos = m_unread + m_unrd_size;
|
curr_pos = m_unread + m_unrd_size;
|
||||||
|
|
||||||
memcpy(curr_pos, buffer, size);
|
memcpy(curr_pos, buffer, size);
|
||||||
|
@@ -160,10 +160,9 @@ bool wxURL::PrepHost(wxString& url)
|
|||||||
// Retrieve service number
|
// Retrieve service number
|
||||||
pos2 = temp_url.Find(':', TRUE);
|
pos2 = temp_url.Find(':', TRUE);
|
||||||
if (pos2 != -1 && pos2 < pos) {
|
if (pos2 != -1 && pos2 < pos) {
|
||||||
m_servname = url(pos2, pos);
|
m_servname = temp_url(pos2+1, pos);
|
||||||
if (!m_servname.IsNumber())
|
if (!m_servname.IsNumber())
|
||||||
return FALSE;
|
return FALSE;
|
||||||
pos2 = pos;
|
|
||||||
temp_url = temp_url(0, pos2);
|
temp_url = temp_url(0, pos2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user