[Issue 17478] New: Socket.select return a write status change, but no connection is established.
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Wed Jun 7 19:50:09 PDT 2017
https://issues.dlang.org/show_bug.cgi?id=17478
Issue ID: 17478
Summary: Socket.select return a write status change, but no
connection is established.
Product: D
Version: D2
Hardware: x86_64
OS: Other
Status: NEW
Severity: critical
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: encounterspring at gmail.com
OS : debian 8
code below:
import std.socket;
import std.stdio;
import std.conv;
bool connect(string host , ushort port , int seconds)
{
import std.stdio;
string strPort = to!string(port);
AddressInfo[] arr = getAddressInfo(host , strPort ,
AddressInfoFlags.CANONNAME);
if(arr.length == 0)
{
writeln("getAddressInfo error");
return false;
}
Socket socket = new Socket(arr[0].family , arr[0].type , arr[0].protocol);
socket.blocking(false);
socket.connect(arr[0].address);
SocketSet writesets = new SocketSet();
writesets.reset();
writesets.add(socket);
TimeVal val;
val.seconds = seconds ;
val.microseconds = 0;
int ret = Socket.select(null ,writesets , null , &val);
if(ret < 0)
{
writeln("some error or interput");
return false;
}
else if(ret == 0)
{
writeln("timeout");
return false;
}
else
{
if(writesets.isSet(socket))
{
writeln("connected");
return true;
}
return false;
}
}
void main()
{
//1234 not listen in my OS. but socket.select show me connected.
connect("127.0.0.1" , 1234 ,3);
}
--
More information about the Digitalmars-d-bugs
mailing list