* Big memory bug fixed in socket/getline fixed.

* Added two missing "virtual" in stream.h (Sorry, you'll have to rebuild all)


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1812 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Guilhem Lavaux
1999-02-27 11:32:10 +00:00
parent ed175610f0
commit 41895a05ea
4 changed files with 40 additions and 18 deletions

View File

@@ -150,7 +150,7 @@ class WXDLLEXPORT wxInputStream: public wxStreamBase {
// IO functions // IO functions
virtual char Peek(); virtual char Peek();
char GetC(); char GetC();
wxInputStream& Read(void *buffer, size_t size); virtual wxInputStream& Read(void *buffer, size_t size);
wxInputStream& Read(wxOutputStream& stream_out); wxInputStream& Read(wxOutputStream& stream_out);
// Position functions // Position functions
@@ -191,7 +191,7 @@ class WXDLLEXPORT wxOutputStream: public wxStreamBase {
wxOutputStream(wxStreamBuffer *sbuf); wxOutputStream(wxStreamBuffer *sbuf);
virtual ~wxOutputStream(); virtual ~wxOutputStream();
wxOutputStream& Write(const void *buffer, size_t size); virtual wxOutputStream& Write(const void *buffer, size_t size);
wxOutputStream& Write(wxInputStream& stream_in); wxOutputStream& Write(wxInputStream& stream_in);
off_t SeekO(off_t pos, wxSeekMode mode = wxFromStart); off_t SeekO(off_t pos, wxSeekMode mode = wxFromStart);

View File

@@ -125,6 +125,7 @@ bool wxHTTP::ParseHeaders()
if (line.Length() == 0) if (line.Length() == 0)
break; break;
printf("Header: %s\n", WXSTRINGCAST line);
int pos = line.Find(':'); int pos = line.Find(':');
if (pos == -1) if (pos == -1)
return FALSE; return FALSE;
@@ -192,6 +193,10 @@ bool wxHTTP::BuildRequest(const wxString& path, wxHTTP_Req req)
return FALSE; return FALSE;
} }
SaveState();
Notify(FALSE);
SetFlags(WAITALL);
sprintf(buf, "%s %s HTTP/1.0\n\r", tmp_buf, (const char *)path); sprintf(buf, "%s %s HTTP/1.0\n\r", tmp_buf, (const char *)path);
Write(buf, strlen(buf)); Write(buf, strlen(buf));
SendHeaders(); SendHeaders();
@@ -201,18 +206,22 @@ bool wxHTTP::BuildRequest(const wxString& path, wxHTTP_Req req)
wxString tmp_str; wxString tmp_str;
m_error = GetLine(this, tmp_str); m_error = GetLine(this, tmp_str);
if (m_error != wxPROTO_NOERR) if (m_error != wxPROTO_NOERR) {
RestoreState();
return FALSE; return FALSE;
}
if (!tmp_str.Contains("HTTP/")) { if (!tmp_str.Contains("HTTP/")) {
// TODO: support HTTP v0.9 which can have no header. // TODO: support HTTP v0.9 which can have no header.
SetHeader("Content-Length", "-1"); SetHeader("Content-Length", "-1");
SetHeader("Content-Type", "none/none"); SetHeader("Content-Type", "none/none");
RestoreState();
return TRUE; return TRUE;
} }
wxStringTokenizer token(tmp_str,' '); wxStringTokenizer token(tmp_str,' ');
wxString tmp_str2; wxString tmp_str2;
bool ret_value;
token.NextToken(); token.NextToken();
tmp_str2 = token.NextToken(); tmp_str2 = token.NextToken();
@@ -222,10 +231,13 @@ bool wxHTTP::BuildRequest(const wxString& path, wxHTTP_Req req)
break; break;
default: default:
m_error = wxPROTO_NOFILE; m_error = wxPROTO_NOFILE;
RestoreState();
return FALSE; return FALSE;
} }
return ParseHeaders(); ret_value = ParseHeaders();
RestoreState();
return ret_value;
} }
class wxHTTPStream : public wxSocketInputStream { class wxHTTPStream : public wxSocketInputStream {
@@ -234,7 +246,7 @@ public:
size_t m_httpsize; size_t m_httpsize;
wxHTTPStream(wxHTTP *http) : wxSocketInputStream(*http), m_http(http) {} wxHTTPStream(wxHTTP *http) : wxSocketInputStream(*http), m_http(http) {}
size_t StreamSize() { return m_httpsize; } size_t StreamSize() const { return m_httpsize; }
virtual ~wxHTTPStream(void) { m_http->Abort(); } virtual ~wxHTTPStream(void) { m_http->Abort(); }
}; };
@@ -258,7 +270,8 @@ wxInputStream *wxHTTP::GetInputStream(const wxString& path)
if (!BuildRequest(path, wxHTTP_GET)) if (!BuildRequest(path, wxHTTP_GET))
return NULL; return NULL;
if (GetHeader("Content-Length").IsEmpty()) printf("Len = %s\n", WXSTRINGCAST GetHeader("Content-Length"));
if (!GetHeader("Content-Length").IsEmpty())
inp_stream->m_httpsize = atoi(WXSTRINGCAST GetHeader("Content-Length")); inp_stream->m_httpsize = atoi(WXSTRINGCAST GetHeader("Content-Length"));
return inp_stream; return inp_stream;

View File

@@ -11,8 +11,6 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__ #ifdef __GNUG__
#pragma implementation "socket.h" #pragma implementation "socket.h"
// #pragma interface
// #pragma implementation "socket.cpp"
#endif #endif
#ifdef __MWERKS__ #ifdef __MWERKS__
@@ -357,31 +355,40 @@ bool wxSocketBase::Close()
wxSocketBase& wxSocketBase::Read(char* buffer, size_t nbytes) wxSocketBase& wxSocketBase::Read(char* buffer, size_t nbytes)
{ {
m_lcount = GetPushback(buffer, nbytes, FALSE); size_t count;
nbytes -= m_lcount;
count = GetPushback(buffer, nbytes, FALSE);
nbytes -= count;
buffer += count;
// 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 || (m_lcount && !(m_flags & WAITALL)) )
return *this; return *this;
m_lcount = 0;
WantBuffer(buffer, nbytes, EVT_READ); WantBuffer(buffer, nbytes, EVT_READ);
m_lcount += count;
return *this; return *this;
} }
wxSocketBase& wxSocketBase::Peek(char* buffer, size_t nbytes) wxSocketBase& wxSocketBase::Peek(char* buffer, size_t nbytes)
{ {
size_t nbytes_old = nbytes; size_t count;
nbytes -= GetPushback(buffer, nbytes, TRUE); count = GetPushback(buffer, nbytes, TRUE);
if (!nbytes) if (nbytes-count == 0)
{ {
m_lcount = nbytes_old; m_lcount = nbytes;
return *this; return *this;
} }
buffer += count;
nbytes -= count;
m_lcount = 0;
WantBuffer(buffer, nbytes, EVT_PEEK); WantBuffer(buffer, nbytes, EVT_PEEK);
m_lcount += count;
return *this; return *this;
} }
@@ -1127,9 +1134,10 @@ void wxSocketBase::CreatePushbackBefore(const char *buffer, size_t size)
curr_pos = new_buf + size; curr_pos = new_buf + size;
memcpy(new_buf, buffer, size); memcpy(new_buf, buffer, size);
memcpy(curr_pos, m_unread, m_unrd_size); if (m_unrd_size != 0) {
memcpy(curr_pos, m_unread, m_unrd_size);
free(m_unread); free(m_unread);
}
m_unread = new_buf; m_unread = new_buf;
m_unrd_size += size; m_unrd_size += size;
} }
@@ -1145,7 +1153,7 @@ size_t wxSocketBase::GetPushback(char *buffer, size_t size, bool peek)
if (!peek) { if (!peek) {
m_unrd_size -= size; m_unrd_size -= size;
if (!m_unrd_size) { if (m_unrd_size == 0) {
free(m_unread); free(m_unread);
m_unread = NULL; m_unread = NULL;
} }

View File

@@ -64,6 +64,7 @@ wxURL::wxURL(const wxString& url)
} }
m_url = url; m_url = url;
m_error = wxURL_NOERR; m_error = wxURL_NOERR;
ParseURL();
} }
bool wxURL::ParseURL() bool wxURL::ParseURL()