www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17478] New: Socket.select return a write status change, but

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 puremagic.com
          Reporter: encounterspring 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);
}

--
Jun 07