|
|
Home » Extra libraries, Code snippets, applications etc. » OS Problems etc., Win32, POSIX, MacOS, FreeBSD, X11 etc » [BUG - solved?] HttpRequest fails under FreeBSD
[BUG - solved?] HttpRequest fails under FreeBSD [message #38711] |
Tue, 08 January 2013 23:36  |
Mindtraveller
Messages: 917 Registered: August 2007 Location: Russia, Moscow rgn.
|
Experienced Contributor |

|
|
This sample (for latest SVN) code fails under FreeBSD
#include <Core/Core.h>
using namespace Upp;
CONSOLE_APP_MAIN
{
HttpRequest::Trace(true);
HttpRequest http("http://google.com"); //fails with almost any sites even w/o redirect
String s = http.Execute();
SaveFile("1", s);
}
It logs error:Quote: | HTTP START
Starting status 2 'Resolving host name', url: google.com
HTTP StartConnect
HTTP AfterConnect
Starting status 6 'Sending request', url: google.com
HTTP REQUEST google.com:0
HTTP request:
GET / HTTP/1.1
URL: http://google.com/
Host: google.com
Connection: close
Accept: */*
Accept-Encoding: gzip
User-Agent: U++ HTTP request
HTTP Execute: Sending request
HTTP retry on error socket(5) / send: Socket is not connected
Starting status 1 'Start', url: google.com
HTTP Execute: Start
HTTP START
Starting status 2 'Resolving host name', url: google.com
HTTP StartConnect
HTTP AfterConnect
Starting status 6 'Sending request', url: google.com
HTTP REQUEST google.com:0
HTTP request:
GET / HTTP/1.1
URL: http://google.com/
Host: google.com
Connection: close
Accept: */*
Accept-Encoding: gzip
User-Agent: U++ HTTP request
HTTP Execute: Sending request
HTTP retry on error socket(5) / send: Socket is not connected
Starting status 1 'Start', url: google.com
HTTP Execute: Start
HTTP START
Starting status 2 'Resolving host name', url: google.com
HTTP StartConnect
HTTP AfterConnect
Starting status 6 'Sending request', url: google.com
HTTP REQUEST google.com:0
HTTP request:
GET / HTTP/1.1
URL: http://google.com/
Host: google.com
Connection: close
Accept: */*
Accept-Encoding: gzip
User-Agent: U++ HTTP request
HTTP Execute: Sending request
HTTP retry on error socket(5) / send: Socket is not connected
Starting status 1 'Start', url: google.com
HTTP Execute: Start
HTTP START
Starting status 2 'Resolving host name', url: google.com
HTTP StartConnect
HTTP AfterConnect
Starting status 6 'Sending request', url: google.com
HTTP REQUEST google.com:0
HTTP request:
GET / HTTP/1.1
URL: http://google.com/
Host: google.com
Connection: close
Accept: */*
Accept-Encoding: gzip
User-Agent: U++ HTTP request
HTTP Execute: Sending request
|
Very strange bug.
Proceeding with investigation...
P.S. Tested on defferent systems with different FreeBSD versions with the same result.
[Updated on: Wed, 23 January 2013 19:47] Report message to a moderator
|
|
|
|
|
|
Re: [BUG] HttpRequest fails under FreeBSD [message #38727 is a reply to message #38726] |
Thu, 10 January 2013 15:26   |
Mindtraveller
Messages: 917 Registered: August 2007 Location: Russia, Moscow rgn.
|
Experienced Contributor |

|
|
Hello, Neil!
Frankly speaking I just did not catch your point.
We have following simple code:
HttpRequest http("http://google.com");
String s = http.Execute();
This code works under Windows. But fails under FreeBSD.
My point is it MUST be working under FreeBSD as well. This is how cross-platform calls work.
You agree, aren't you?
[Updated on: Thu, 10 January 2013 15:42] Report message to a moderator
|
|
|
|
|
Re: [BUG] HttpRequest fails under FreeBSD [message #38733 is a reply to message #38731] |
Thu, 10 January 2013 20:33   |
Mindtraveller
Messages: 917 Registered: August 2007 Location: Russia, Moscow rgn.
|
Experienced Contributor |

|
|
OK, finally managed to find a possible cause of this misfunction. In simple words, under FreeBSD, connecting socket didn't finish at the moment when we start sending data through it. Which resulted in failure with error code "Socket not connected".
So here is my solution which seems to work but may be not that good.
(Core/Socket.spp)
bool TcpSocket::RawConnect(addrinfo *arp)
...
//@445 +++
if (GetErrorCode() == SOCKERR(EINPROGRESS))
WaitWrite();
// +++
If you know better solution how to detect the need and wait socket connection, please propose it.
[Updated on: Fri, 11 January 2013 13:05] Report message to a moderator
|
|
|
|
|
|
|
Re: [BUG] HttpRequest fails under FreeBSD [message #38873 is a reply to message #38872] |
Thu, 24 January 2013 22:39   |
Mindtraveller
Messages: 917 Registered: August 2007 Location: Russia, Moscow rgn.
|
Experienced Contributor |

|
|
After a bunch of experiments I've finally come to code which works under one of my test FreeBSD systems I currently work in. Tomorrow I'll test it under different FreebBSD system to be absolutely sure about it.
For now, here is WouldBlock() function which seems like a solution:
bool TcpSocket::WouldBlock()
{
int c = GetErrorCode();
#ifdef PLATFORM_POSIX
#ifdef PLATFORM_BSD
if(c == SOCKERR(ENOTCONN))
return true;
#endif
return c == SOCKERR(EWOULDBLOCK) || c == SOCKERR(EAGAIN);
#endif
#ifdef PLATFORM_WIN32
if(c == SOCKERR(ENOTCONN) && !IsNull(connection_start) && msecs(connection_start) < 20000) {
LLOG("ENOTCONN issue");
return true;
}
return c == SOCKERR(EWOULDBLOCK);
#endif
}
[Updated on: Thu, 24 January 2013 22:40] Report message to a moderator
|
|
|
|
|
|
Re: [BUG] HttpRequest fails under FreeBSD [message #38893 is a reply to message #38885] |
Fri, 25 January 2013 22:20   |
Mindtraveller
Messages: 917 Registered: August 2007 Location: Russia, Moscow rgn.
|
Experienced Contributor |

|
|
Timeout check added.
Index: Socket.cpp
===================================================================
--- Socket.cpp (revision 5727)
+++ Socket.cpp (working copy)
@@ -268,7 +268,7 @@
sslinfo.Clear();
start_time = Null;
global_timeout = Null;
-#ifdef PLATFORM_WIN32
+#if (PLATFORM_WIN32 || PLATFORM_BSD)
connection_start = Null;
#endif
ssl_start = Null;
@@ -293,6 +293,9 @@
return false;
}
#else
+ #if (PLATFORM_BSD)
+ connection_start = msecs();
+ #endif
if(fcntl(socket, F_SETFL, (fcntl(socket, F_GETFL, 0) | O_NONBLOCK))) {
SetSockError("fcntl(O_[NON]BLOCK)");
return false;
@@ -509,7 +512,12 @@
{
int c = GetErrorCode();
#ifdef PLATFORM_POSIX
- return c == SOCKERR(EWOULDBLOCK) || c == SOCKERR(EAGAIN);
+ #ifdef PLATFORM_BSD
+ DUMP(connection_start);
+ if(c == SOCKERR(ENOTCONN) && !IsNull(connection_start) && msecs(connection_start) < 20000)
+ return true;
+ #endif
+ return c == c == SOCKERR(EWOULDBLOCK) || c == SOCKERR(EAGAIN);
#endif
#ifdef PLATFORM_WIN32
if(c == SOCKERR(ENOTCONN) && !IsNull(connection_start) && msecs(connection_start) < 20000) {
@@ -599,7 +607,7 @@
return false;
}
if(avail > 0) {
- #ifdef PLATFORM_WIN32
+ #if (PLATFORM_WIN32 || PLATFORM_BSD)
connection_start = Null;
#endif
return true;
@@ -630,7 +638,7 @@
{ // Compute time limit for operation, based on global timeout and per-operation timeout settings
int o = min(IsNull(global_timeout) ? INT_MAX : start_time + global_timeout,
IsNull(timeout) ? INT_MAX : msecs() + timeout);
-#ifdef PLATFORM_WIN32
+#if (PLATFORM_WIN32 || PLATFORM_BSD)
if(GetErrorCode() == SOCKERR(ENOTCONN) && !IsNull(connection_start))
if(msecs(connection_start) < 20000)
o = connection_start + 20000;
Index: Inet.h
===================================================================
--- Inet.h (revision 5727)
+++ Inet.h (working copy)
@@ -88,7 +88,7 @@
int global_timeout;
int start_time;
-#ifdef PLATFORM_WIN32
+#if (PLATFORM_WIN32 || PLATFORM_BSD)
int connection_start;
#endif
int ssl_start;
[Updated on: Fri, 25 January 2013 22:22] Report message to a moderator
|
|
|
|
|
|
Goto Forum:
Current Time: Fri Apr 25 13:11:09 CEST 2025
Total time taken to generate the page: 0.02696 seconds
|
|
|