Hi!

I am having problems using select in that it seems to suceed and fail at the same time....

; --------------------------------------------------------------------------

invoke connect,sock,ADDR sin,SIZEOF sin

invoke select, NULL, addr mysocket, NULL, NULL, addr timeout

.if eax==0

invoke MessageBox,hWnd,addr unableconnect,addr caption,MB_OK

.elseif eax==SOCKET_ERROR

invoke MessageBox,hWnd,addr sockerror,addr caption,MB_OK

.else

invoke MessageBox,hWnd,addr connected,addr caption,MB_OK

.endif

; --------------------------------------------------------------------------

when it cant connect its fine and shows the MessageBox.
but when it can connect it shows the unable to connect message but still connects.

all i want to do is establish whether the connection was successfull.

Please help... ...
thanks.
skud.
Posted on 2001-08-25 14:28:32 by skud
The problem is the wrong use of select: select wants an FD_SET structure as parameters, not just a pointer to the socket handle alone.
An FD_SET structure starts with one DWORD that identifies the number of sockets you want to check something for, in your case 1. Then immediately following this DWORD, there is a DWORD array of socket handles.
The easiest solution for you is to do this:


.data?
;FD_SET structure starts here
SockSet dd ?
mysocket dd ?
;FD_SET structure ends here
;do not rearrange both variables!

Then in your code still use mysocket, but the select becomes:


mov SockSet, 1 ;this sets the first dword (sockhandle count) to 1 socket
invoke select, NULL, addr SockSet, NULL, NULL, addr timeout

That should do it

Thomas
Posted on 2001-08-25 14:48:14 by Thomas
i have done that already:

.data?

SOCKSET STRUCT
dwCount DWORD ?
dwSocket DWORD ?
SOCKSET ENDS

mysocket SOCKSET <?>
timeout timeval <?>

...

mov mysocket.dwSocket, eax
mov mysocket.dwCount, 1
mov timeout.tv_sec, 3
mov timeout.tv_usec, NULL

it is working properly... kind of....
its just not doing what i want :D

thanks anyway ;)
skud.
Posted on 2001-08-25 15:43:50 by skud
:( Sorry I missed that, should have seen you used two different variables.. anyways, they only reason I can think of is that 0 indicates timeout has expired, not that the connection has failed, maybe 3 seconds is too short...but seems unlikely..

Thomas
Posted on 2001-08-25 17:14:25 by Thomas
yeah 3000ms is quite a long time :) ... especially as im testing it on my local computer.

should i check for writeability or readibility to tell whether the connection is established??

thx.
skud.
Posted on 2001-08-25 17:24:03 by skud
hmm no should not be a problem on a local computer :grin:, are you working with blocking sockets? in that case, you don't need select:


Return Values (of connect)

If no error occurs, connect returns zero. Otherwise, it returns SOCKET_ERROR, and a specific error code can be retrieved by calling WSAGetLastError.
On a blocking socket, the return value indicates success or failure of the connection attempt.


Thomas
Posted on 2001-08-25 17:40:14 by Thomas
non-blocking mode
"Problem using select in non-blocking mode"

:)
Posted on 2001-08-25 18:01:44 by skud
Hmm I think I see the problem here, shouldn't you use the writefds parameter instead of the readfds parameter?


readfds:

    [*] If listening, a connection is pending, accept will succeed
    [*] Data is available for reading (includes OOB data if SO_OOBINLINE is enabled)
    [*] Connection has been closed/reset/terminated


    writefds:

      [*] If connecting (nonblocking), connection has succeeded
      [*] Data can be sent

Posted on 2001-08-26 03:18:42 by Thomas
i have tried both :P

when i check for write and it shouldnt connect, then it says connnected after the timeout, ie. it doesnt return NULL or SOCKET_ERROR....

if it should be able to connect then it returns instantly.

my code:

; ---------------------------------------------------------------------

.data?

wsadata WSADATA <?>
sin sockaddr_in <?>
mysocket SOCKSET <?>
timeout timeval <?>

SOCKSET STRUCT
dwCount DWORD ?
dwSocket DWORD ?
SOCKSET ENDS

.code

...

invoke connect,sock,ADDR sin,SIZEOF sin

invoke select, NULL, NULL, addr mysocket, NULL, addr timeout

.if eax==0

invoke MessageBox,hWnd,addr unableconnect,addr caption,MB_OK

.elseif eax==SOCKET_ERROR

invoke MessageBox,hWnd,addr sockerror,addr caption,MB_OK

.else

invoke MessageBox,hWnd,addr connected,addr caption,MB_OK

.endif

; ---------------------------------------------------------------------

If anyone has a working example of using select to check if the connection was successfull (non-blocking mode) then that would be great.... or any other method at that.

thx.
skud.
Posted on 2001-08-26 04:13:42 by skud
I only use select on blocking mode sockets, and WSAsyncSelect on non-blocking sockets, with WSAsyncSelect, the notifications are correct...
Posted on 2001-08-26 17:16:47 by Thomas