Re: Socket switch delay

From: Alexander Nickolov (agnickolov_at_mvps.org)
Date: 08/24/04

  • Next message: Alexander Nickolov: "Re: Socket switch delay"
    Date: Tue, 24 Aug 2004 13:17:31 -0700
    
    

    Your sever side send is never partial - it's overlapped. All your
    buffers are queued and will be later sent. You must preserve
    them until notified (BTW, I didn't see any code of yours to
    deal with the notification - you pass NULL event handle and
    NULL APC...). Or at least that's the behavior with a non-blocking
    socket, not sure about a blocking socket. (And I'm not even
    sure it matters if the socket is blocking or not.)

    -- 
    =====================================
    Alexander Nickolov
    Microsoft MVP [VC], MCSD
    email: agnickolov@mvps.org
    MVP VC FAQ: http://www.mvps.org/vcfaq
    =====================================
    "mil" <mil@discussions.microsoft.com> wrote in message 
    news:B70055F9-BDAD-4D2E-990C-EB5AB3AD93B9@microsoft.com...
    >
    > "Alexander Nickolov" wrote:
    >
    >>(and I noticed you don't do overlapped receive at the server!)
    >
    >
    > The receive operation in the server is overlapped, first I receive a 
    > header
    > which describes what is coming (with one recv competion io) and then I 
    > setup
    > buffers and wait for all the data I should be receiving, through the
    > completion IO. If not all the data comes back, I calculate the right 
    > offsets
    > and wait again for the completion io.
    >
    > I didn't send you that part of the code because it is too long.
    >
    >
    >>would you set the send buffer size to zero on a non-overlapped
    >>socket escapes me...).
    >
    > So I get better performance(?) Since I am sending all the data at once 
    > using
    > WSA buffers why do I need to copy them again? Of course I changed that in 
    > the
    > server (so the user can disable the 0 buffering, maybe I should make it
    > optional in the client too).
    >
    >
    >>One glaring error is your client does not check it sent all data in one go
    >
    >
    > Hmm, you are right. I thought when I send data it always sends them all or
    > it returns an error. I also thought that only the receive can send partial
    > buffers where the send always sends the whole thing or nothing.
    >
    > I think I got this whole thing wrong.
    >
    >
    >
    >>though I have no idea if this is your problem. So when you use a >single 
    >>socket, what exactly happens with this code and on which >side?
    >
    > If the previous assumption of mine, is wrong, then that must be the 
    > problem.
    > Because when the client sends data while the server also sends data, the
    > connection fails and the server socket stays locked for a minute or two.
    >
    >
    >>Finally, I've never mixed overlapped with non-overlapped I/O
    >>on the same socket. Could that be your problem?
    >
    > I didn't mix the two models, only the client is not using Overlapped IO. 
    > The
    > server is using it for all communication and file writing.
    >
    >
    > The problem must be the fact that I don't "expect" the send command to 
    > send
    > partial buffers. And I am not taking into account that in both the client 
    > and
    > the server code. Where for the receive, I "obey" the rules.
    >
    > So only when I am using a single socket and both client and server are
    > sending data, the send-operation does not send all the buffers in one go 
    > and
    > "asks me" to try again (and my code doesn't handle this condition).
    >
    > I am not saying that this cannot happen with the current code as well, but
    > it seems that it mostly happens when both sides try to talk over the same
    > socket.
    >
    > I will change the code accordingly to take this into account at both 
    > sides.
    >
    > Thanks for pointing out all these "omissions" (to put it kindly) in my 
    > code ;)
    >
    > Now back to the drawing board for me :(   I am going to add the checking 
    > for
    > the send operations in client and server then try again with a single 
    > socket.
    >
    > mil
    >
    >
    > 
    

  • Next message: Alexander Nickolov: "Re: Socket switch delay"

    Relevant Pages

    • Re: Socket switch delay
      ... both at the client and at the server (and why ... would you set the send buffer size to zero on a non-overlapped ... One glaring error is your client does ... So when you use a single socket, ...
      (microsoft.public.win32.programmer.networks)
    • Re: Locking on async calls
      ... you must synchronize the entire SendMessage routine as an atomic ... operation to prevent mixed messages from being transmitted to the server. ... You are correct that read and write on the socket do not interfere with each ... If you want to handle multiple client connections from one server object ...
      (microsoft.public.dotnet.general)
    • Re: TCP server stop receiving new connections
      ... reset the event mask of your listening socket each time you ... I have a strange problem in my class library used by all our client ... server applications. ... incomming connections, but keeps current connections. ...
      (microsoft.public.win32.programmer.networks)
    • Re: Design issue with WinSock/GetQueuedCompletionStatus
      ... delegate that to a shutdown routine called after all worker threads ... The application I've created is a server accepting connections on a few ... different TCP/IP ports and then lets the client run different commands. ... a TCP/IP socket can be closed for 2 different reasons: ...
      (microsoft.public.win32.programmer.networks)
    • Re: socket communication: socket doesnt connect
      ... Microsoft MVP, MCSD ... As far as your server code goes, ... accept the listening socket. ... Client client = new Client; ...
      (microsoft.public.vc.language)