flat assembler
Message board for the users of flat assembler.

Index > Windows > Winsock Trouble..

Author
Thread Post new topic Reply to topic
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 17 Dec 2011, 12:22
Hello everyone, I got some problems on winsock when trying to receive same time from different sockets..
First of all, I have 2 sockets, and first is waiting for data to be received, the second will be created in thread, which will wait to receive another data.. But problem is that, program won't continue executing, until thread's recv will receive data.. I was thinking a lot but I don't understand what is the problem.. Here's code:
Code:
proc blah
......
@@:
        invoke recv,[hSock],dstbuff,1024,0
        invoke send,[rSock],dstbuff,eax,0
        push eax
        invoke CreateThread,0,0,threadproc,0,0,0
        cinvoke printf,<"[+] Packets sent!",0x0a,0>
        pop eax
        test eax,eax
        jg @b
.cleanup:
        invoke closesocket,[hSock]
        invoke closesocket,[rSock]
        invoke WSACleanup
        invoke Sleep,100
        ret
endp

proc threadproc stdcall
        invoke recv,[rSock],srcbuff,1024,0 ;<-- stucks here until it receives data! WHY ?
        invoke send,[hSock],srcbuff,eax,0
       ret
endp    
Post 17 Dec 2011, 12:22
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 17 Dec 2011, 12:51
RTFM
TFM wrote:
If no incoming data is available at the socket, the recv call waits for data to arrive unless the socket is nonblocking. In this case, a value of SOCKET_ERROR is returned with the error code set to WSAEWOULDBLOCK. The select, WSAAsyncSelect, or WSAEventSelect calls can be used to determine when more data arrives.
Post 17 Dec 2011, 12:51
View user's profile Send private message Visit poster's website Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 17 Dec 2011, 12:54
revolution
I know that but:
1) It's running to another thread. Why thread are pausing my program ?
2) How to use blocking sockets ? I have no idea.
Post 17 Dec 2011, 12:54
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 17 Dec 2011, 13:02
Overflowz wrote:
I know that but:
If you took the time to explain what you know and what you tried then we won't just assume you didn't know and you would get better quality answers. Wink
Overflowz wrote:
1) It's running to another thread. Why thread are pausing my program ?
Your main thread also has a recv. And since you didn't post all your code I have no idea what you are doing or what you mean by "pausing your program".
Overflowz wrote:
2) How to use blocking sockets ? I have no idea.
TFM explains it.
Post 17 Dec 2011, 13:02
View user's profile Send private message Visit poster's website Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 17 Dec 2011, 13:26
I posted the code, which are running in different thread and I have problem only there, not else anywhere, so, I said thread's recv is waiting data until it receives and by that time, program execution is passed to only that thread, I mean, program waits that thread and then continues execution (I hate English).
and what TFM mean I really don't know. Be more understandable please.
Post 17 Dec 2011, 13:26
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 17 Dec 2011, 13:44
So after the thread is created does you code print "[+] Packets sent!"? And after printing "[+] Packets sent!" your code loops around and waits on another recv
Code:
@@:
        invoke recv,[hSock],dstbuff,1024,0 ;wait here also
        invoke send,[rSock],dstbuff,eax,0     
How do you know where your code is waiting? With multiple threads it can be tricky to know which is waiting for what. How do you use your debugger to determine what happened?

I suspect you are looking in the wrong place, and that is why you need to post all the code, or at the very least a working example showing the problem. Give us something we can compile and run to see what is happening. Help us to help you.

The reason I suspect you are looking in the wrong place is because a single thread waiting on a blocking API call cannot "pause you whole program". The other threads will continue to run normally. You have to find out where the other threads are and what they are waiting on.
Post 17 Dec 2011, 13:44
View user's profile Send private message Visit poster's website Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 17 Dec 2011, 14:03
revolution
I found problem, sorry, problem is in loop. I'm creating thread in loop even if threadproc is not receiving data..
Thank you Smile
Post 17 Dec 2011, 14:03
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 17 Dec 2011, 17:46
Not going to open another thread, just asking here.. How should I set option to socket to be Non-Blocking ? Should I use ReadFile/WriteFile instead of recv/send ?
Post 17 Dec 2011, 17:46
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 18 Dec 2011, 08:45
Never mind, I found. It is done with ioctlsocket API.
Post 18 Dec 2011, 08:45
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.