Re: Can 2 Threads initiate Overlapped I/O (WSARecv / WSASend) on same socket?

> > > OS: Windows XP Professional

> > API: Winsock 2.0
> >
> > 1. Can 2 Threads initiate overlapped I/O operation (one:
WSARecv( )
> > other: WSASend( )) on SAME socket at the SAME TIME ?

The “tribal lore” on this topic strongly suggests that a single socket
should be managed by a single thread. I learned this lesson the hard
way,
years ago, and can’t remember the details of what went wrong and why
it’s
so… but trust me, you’ll spend far less time debugging if you
maintain a
1:1 socket:thread relationship.

I’m not sure if this is related, but Windows sockets will actually use a
window for receiving socket notifications and events. This window is
tied to the thread that created it. I encountered problems if I tried
to use the socket from a thread other than the one that created it.

Chuck

> I’m not sure if this is related, but Windows sockets will actually
use a

window for receiving socket notifications and events.

Ancient version only, though this functionality is supported for
backward compatibility even now. The modern WinSock is not tied to
window management in any way except this backward compatibility hack.

Using Berkeley routines on NT4, it is fine to use socket from
different threads, I remember doing this in late 1996.

Max

First, thanks to all who replied.

Actually it works fine. We no need to maintain one-to-one between socket
& thread.
Because some other issue, it seemed that it wasn’t working.

Still, there is one more issue.

After I initiate WSASend / WSARecv, I am getting status by
WSAGetOverlappedResult.
What happens is, WSAGetOverlappedResult( ) returns true but num bytes
transferred = 0.
(please note that I am waiting till the transfer is completed).

Earlier I didn’t check this condition that num bytes transferred = 0.

I can’t understand this behaviour.

Thanks,
Sathya

===================================
Knowledge, Skill and desire will lead to SUCCESS.

-----Original Message-----
From: Richard L Hartman [mailto:xxxxx@realresume.com]
Sent: Friday, June 06, 2003 10:45 PM
Subject: Re: Can 2 Threads initiate Overlapped I/O (WSARecv / WSASend)
on same socket?

> OS: Windows XP Professional
> API: Winsock 2.0
>
> 1. Can 2 Threads initiate overlapped I/O operation (one: WSARecv( )
> other: WSASend( )) on SAME socket at the SAME TIME ?

The “tribal lore” on this topic strongly suggests that a single socket
should be managed by a single thread. I learned this lesson the hard
way,
years ago, and can’t remember the details of what went wrong and why
it’s
so… but trust me, you’ll spend far less time debugging if you maintain
a
1:1 socket:thread relationship.

Hope this helps!

RLH