NonBlocking Socket Connect Error Code - EINPROGRESS

When initializing socket with nonblocking mode and connect to, it usually returns error code -1, SE_EINPROGRESS.

bool FSocketBSD::Connect(const FInternetAddr& Addr)
{
	int32 Return = connect(Socket, (sockaddr*)(FInternetAddrBSD&)Addr, sizeof(sockaddr_in));
	
	check(SocketSubsystem);
	ESocketErrors Error = SocketSubsystem->TranslateErrorCode(Return);

	// "would block" is not an error
	return ((Error == SE_NO_ERROR) || (Error == SE_EWOULDBLOCK));
}

But in nonblocking mode, when facing this error code, usually someone needs to check socket status with select/poll whatever for checking read/write status later.
so in somewhat means it’s not the error situation for handling as error right returning from connect function.

is there any good idea for handling this error code?

Hey belliny.kim,

Can you please tell me what you mean by this?:

so in somewhat means it’s not the error situation for handling as error right returning from connect function.

Thanks.

Hello,

Thank you for reviewing my post.

i’ve wrote below code for connect to server,

	// Endpoint, initializing w/ destination info
	FIPv4Endpoint Endpoint;
	.......

	// allocate new socket, nonblocking mode
	Socket = FTcpSocketBuilder(TEXT("...")).AsReusable().AsNonBlocking();
	if (true == Socket->Connect(*Endpoint.ToInternetAddr()))
	{
		return true;
	}
	else
	{
		// EINPROGRESS is returned
		// do something for handling this situation
	}

and, below code(not exactly same, it’s abs. form) for monitoring socket status within every tick(or runnable thread)

	if (nullptr == Socket)
	{
		return;
	}
	
	ESocketConnectionState eNewSockState = Socket->GetConnectionState();
	if (ESocketConnectionState::SCS_Connected == eNewSockState)
	{
		// connected to server
	}
	else if (...)
	{
		// do something else
		...
	}

even i’ve got EINPROGRESS(Connect function returns false as it’s not SE_NO_ERROR nor SE_EWOULDBLOCK), socket is still working in async and got connection if it’s reachable to server.

Hey belliny.kim,

This issue has already been logged and is being tracked. You can follow it here:

https://issues.unrealengine.com/issue/UE-2248

Thanks!
it’s been so long time past since the UE-2248 posted. :frowning:
I hope it’ll be soon progressed.