Thread: winsock internal buffers

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    288

    winsock internal buffers

    i was reading through some of the older topics and found this post:

    Quote Originally Posted by Salem
    Try sending a large file somewhere, and see how long each successive call to send() takes.

    Before long, you'll see send() taking a lot longer than it used to (because all the interal buffers are full), and you have to wait around for them to clear.
    on this topic: http://cboard.cprogramming.com/showt...t=61876&page=2

    anyway, my question is:

    after reading that topic, i noticed it actually does happen. I tried sending a 800kb file (in 4 kb chunks) and the first 5% or so went fine, then it started slowing down, and eventually, it wud pause for up to 2 seconds or so.

    so i was wondering, how can i flush these internal buffers?

    edit:

    im using blocking sockets to send the data (incase you needed to know that)
    Last edited by X PaYnE X; 05-16-2005 at 02:31 AM.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    I'm not sure that there's anything you can do to improve this situation. Winsock will clear buffer space as it is able to send data out over the network. You just have to wait the time it takes to send.

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    288
    using blocking sockets, im kind of forced to wait until it sends... doesnt it clear or flush the buffer automatically after it sends the data successfully?

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Even with blocking sockets send returns before the data has been sent. It takes more time to send data out over the network then it dose to call the send function. So the first few times you call send data is just added to the internal buffers ready to be sent and send() returns while winsock is working it's way thru the data to be sent. The only time send blocks is when there is no room left in the internal buffers in which case it will return when there is room to add your data. If there was a flush function it would still take the same amount of time to get rid of the data onto the network.

  5. #5
    Registered User
    Join Date
    Aug 2003
    Posts
    288
    ok, so can i help reduce this problem by increasing/decreasing the packet size? its currently set at 4 kb, ive noticed that when i set it to 256 bytes it doesnt pause as much but it does take longer overall.

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Quote Originally Posted by X PaYnE X
    ok, so can i help reduce this problem by increasing/decreasing the packet size? its currently set at 4 kb, ive noticed that when i set it to 256 bytes it doesnt pause as much but it does take longer overall.
    Larger packet sizes tend to be more efficant however if you use smaller packet sizes then it will take less time for that amount of space to become available in the internal buffers.
    If you would rather be doing other things then waiting for send() calls to complete consider switching to asynchronous sockets or try something like:
    call select() with a low timeout value to determine weather the socket is ready to be written to.
    If it is send the next chunk of data.
    If not do something usefull.
    *Note I havn't tried this meathod
    *Note calling select in a loop with a low timeout isn't very efficant in terms of CPU ussage.
    Last edited by Quantum1024; 05-16-2005 at 04:08 AM.

  7. #7
    Registered User
    Join Date
    Aug 2003
    Posts
    288
    actually, i dont need to do anything while its sending, i set up the send loop in a thread, basically it just sends a file over the internet.. i set up an upload speed counter, but everytime the send function pauses it messes up the upload speed value, so im trying to find a way to eliminate that.

  8. #8
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    The thing is that the time it takes to do the first few send calls dosen't represent the time it took to send that amount of data jus the time it takes to fill th internal buffers, I'm not sure of the most acurate way to calculate upload speeds.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Winsock issues
    By tjpanda in forum Windows Programming
    Replies: 3
    Last Post: 12-04-2008, 08:32 AM
  2. output buffers vs. internal ones?
    By drrngrvy in forum C++ Programming
    Replies: 1
    Last Post: 03-06-2006, 08:32 PM
  3. Winsock Messaging Program
    By Morgul in forum Windows Programming
    Replies: 13
    Last Post: 04-25-2005, 04:00 PM
  4. Where do I initialize Winsock and catch messages for it?
    By Lithorien in forum Windows Programming
    Replies: 10
    Last Post: 12-30-2004, 12:11 PM
  5. winsock
    By pode in forum Networking/Device Communication
    Replies: 2
    Last Post: 09-26-2003, 12:45 AM