Guidance Forums / wxWidgets (wxWindows) in C++ / Stream problems

Search 搜索
Home Home

Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Stream problems
Posted by: lea 2003-11-25 17:53:00
wxURL url(_T("myurl"));
wxInputStream *in_stream = url.GetInputStream();
wxString in;
char inp;

I have:
while((inp = in_stream->GetC()) != -1 ) {
              in += inp;

That works, but when i have:

while((inp = in_stream->GetC()) != -1 ) {
              in += inp;

the end of stream is not found and the loop is infinitve.

Whats wrong here?
I tried various other stream (buffered, text, etc...) and none found the stream end.
in_stream->Eof() does not work either, only -1 and only with this AppendText() call.

Message2. Re: Stream problems
Posted by: 2003-11-25 22:23:32
Hi Lea, I think the inet streams are buggy, I've had simerlar problems. I got as far as this:

wxString UrlError(int a)
wxString temp;
case wxURL_NOERR:  temp =  "No error";break;  
case wxURL_SNTXERR:  temp =  "Syntax error in the URL string.";break;  
case wxURL_NOPROTO:  temp =  "Found no protocol which can get this URL.";break;  
case wxURL_NOHOST:  temp =  "An host name is required for this protocol.";break;  
case wxURL_NOPATH:  temp =  "A path is required for this protocol.";break;  
case wxURL_CONNERR:  temp =  "Connection error.";break;  
case wxURL_PROTOERR:  temp =  "An error occurred during negotiation.";break;
default: temp =  "Unknown error";break;
return temp;
int GetAsString(wxString& ac, wxString ca)
//    wxFileSystem* temp = new wxFileSystem();
//    wxInputStream *in_stream;
//    in_stream = (temp->OpenFile(dlg.ThankYou()))->GetStream();    
//    //in_stream->Read(*out_stream);
//    wxStreamBuffer *out_stream(in_stream, 'wxStreamBuffer::read');
    wxURL url(ca);
    if(url.GetError() != wxURL_NOERR )
    return -1;}
    wxInputStream *in_stream;
    in_stream = url.GetInputStream();
    if(url.GetError() != wxURL_NOERR )
    return -1;}
    wxString buff;
    in_stream->Read(buff.GetWriteBuf(1024), 1024);
    ac += buff;
    } while((in_stream->IsOk()));

    wxString blag;
    blag.sprintf("yip: %d yap: %d yop: %d", wxSTREAM_READ_ERROR , in_stream->LastError(), ac.Len());
    return 1;
    return -1;
But it still has bizarre behaivour, like bailing a block early and giving an unexplained error when a '?' appears in the url, which makes no sense. I've given up on that method and am working on a library of functions using wxWindows' socket interface.
Message3. Re: Stream problems
Posted by: lea 2003-11-25 22:31:17
Hm, doesn't sound good!

I found this:
// Parse the URL
  wxURL url(urlname);
  if (url.GetError() != wxURL_NOERR)
    m_text->AppendText(_("Error: couldn't parse URLn"));
    m_text->AppendText(_("=== URL test ends ===n"));

  // Try to get the input stream (connects to the given URL)
  m_text->AppendText(_("Trying to establish connection...n"));
  wxInputStream *data = url.GetInputStream();
  if (!data)
    m_text->AppendText(_("Error: couldn't read from URLn"));
    m_text->AppendText(_("=== URL test ends ===n"));

  // Print the contents type and file size
  wxString s;
  s.Printf(_("Contents type: %snFile size: %inStarting to download...n"),

But this doesn't work either, the data->GetSize() is -1, but that is said in the docs.
So no help here.

I have a theory, what causes my problem.
Reading the inputstream is asyncron and does not wait with the next read for a ready stream.
So the stream is not ready when requested and goes to an illigal state.
When i put the text to screen, there is time for the stream to get ready.
But what is that for a bullshit? (sorry for the harsh words)

Any comments?
Message4. Re: Stream problems
Posted by: lea 2003-11-25 22:37:22
Ha, it worked with inputStream.IsOk().
Wired, wired...(i am nearly sure i tried that before)

Thanks Adam!
Message5. Re: Stream problems
Posted by: lea 2003-11-25 22:51:53
I tried this, but some chars (in the whole string) in the result where corrupted.

wxString in;
unsigned char buffer[128]; //same with char    
while(in_stream->IsOk()) {
     in_stream->Read(buffer, 128);

only this works for me

wxString in;
while(in_stream->IsOk()) {    
    in += in_stream->GetC();               

Are the streams really buggy?
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
© Fri 2024-6-21  Guidance Laboratory Inc. Hits:0