Bug 17478 – Socket.select return a write status change, but no connection is established.

Status
RESOLVED
Resolution
WONTFIX
Severity
critical
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Other
Creation time
2017-06-08T02:50:00Z
Last change time
2017-06-09T03:06:48Z
Assigned to
nobody
Creator
encounterspring

Comments

Comment #0 by encounterspring — 2017-06-08T02:50:09Z
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); }
Comment #1 by dlang-bugzilla — 2017-06-08T12:23:25Z
std.socket is just a simple translation layer to C APIs. Does the same program written in C behave differently?
Comment #2 by encounterspring — 2017-06-09T03:06:48Z
thanks for your reply. i misunderstand the c's api select. Either established or error occurred , a write status will change. i'm afraid the d document [https://dlang.org/library/std/socket/socket.select.html] has a little mistake. for a connecting socket , a writet status change . may establelished or error occurred.