Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ MT-multithreading and servers » [SOLVED] TcpSocket Connect error
Re: TcpSocket Connect error [message #42416 is a reply to message #42396] Wed, 12 March 2014 17:24 Go to previous messageGo to previous message
steffen is currently offline  steffen
Messages: 38
Registered: May 2007
Location: Denmark
Member

Thanks Mirek,

But what about the return value? I would expect TcpSocket.Connect to return true, when it has established a connection.
This is definitely not how it works, if the server is not responding.

I looked at the Linux man page on connect and for non blocking connections it says the following:
Quote:

EINPROGRESS
The socket is nonblocking and the connection cannot be completed immediately.
It is possible to select(2) or poll(2) for completion by selecting the socket for writing.
After select(2) indicates writability, use getsockopt(2) to read the SO_ERROR option at level
SOL_SOCKET to determine whether connect() completed successfully (SO_ERROR is zero) or unsuccessfully
(SO_ERROR is one of the usual error codes listed here, explaining the reason for the failure).


I have attached a small example showing the error and the solution mentioned in the man page:
When connecting to a non existing server, TcpSocket.Connect returns true, but fails on a subsequent write.

I have tested the example on both Windows and Linux, and both systems has the error.

So a solution could be one of these two:
1. Change TcpSocket::SetupSocket() to make a blocking socket:
Change Socket.cpp line 302 to
	if(fcntl(socket, F_SETFL, (fcntl(socket, F_GETFL, 0)))) {

or
2. Implement the getsockopt call to check the connection before returning from RawConnect.
I can make a patch to RawConnect if you would prefer that solution.

[Updated on: Wed, 12 March 2014 17:25]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: SSL handshake error
Next Topic: How to use Skylark on external server
Goto Forum:
  


Current Time: Mon Jun 10 23:24:33 CEST 2024

Total time taken to generate the page: 0.01800 seconds