Thread: Pair of networking questions

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    13

    Pair of networking questions

    I haven't had much luck with these in other places, but its still worth trying.


    1)The BSD socket options SNDLOWATER and RCVLOWATER are not supported in Windows. THeir purpose is to alter the select() call to return only when a RCVLOWATER bytes are ready for input or SNDLOWATER for output. I can emulate this functionality for reieving, but not sending. Any ideas on how this could be done?


    2)A related question- I want a function to peek at n bytes from a socket, or quite if timeout milliseconds pass. In Unix, I could select with n as the rcv low water mark, and read when it returns. In windows, that doesn't work. MY best ideas are to either use an async event to see when data arrives, check if the recv buffer has the data, and if not, clear the event and select again. Is that legal? If not, I could emulate select with successive sleeps and polling. But thats uglier.

    If anyone can help, I'd be greatful.

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Have you looked at WSA?

    Tried defining your own windows msgs for socket events?

    Look for WSAAsyncSelect() to get windows msg's (FD_READ, FD_CONNECT) for socket events.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    13
    I have. THis function is for a program that needs to be used in both Unix and windows, going async is not an option. The call Im using needs to be blocking, to match in functionality with the unix version.

    In addition, I believe it still doesnt support the functionality I need out of it- I would need to not be notified until there are n bytes in the buffer. Unix has this ability. WSAAsyncSelect would signal an event if there was any buffer room, even 1 byte. So it doesn't quite fill my needs. Its nonblocking version- WSAEventSelect, can be kluged into doing so if it is legal to use ResetEvent on a WSAEvent, and if it will be signalled correctly after doing so. But Im unsure if thats legal. Its one of the options, along with emulation with sleep and polling, that I will try if I can't find a way to support this feature otherwise.

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    My Windows app recieves many different data sizes.
    I just send the size expected if not known (ie an image which can vary). Until this size is reached the app continues to read in response to the FD_READ's. When all the data has arrived it is then processed.

    If a send() is WOULDBLOCKED, a buffer is created for the unsent data. On a FD_WRITE msg (ie the socket is clear) the buffer is retried. While waiting for the FD_WRITE the buffer is increased as more data is sent to that socket (I have multiple). The user is warned to slow down the sends.


    I don't have to deal with *NIX only MS OS's.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    46
    Here's an idea to try. Use an Async socket to check to see if the buffer is full. if it's not, wait a set amount of time and check again. Only use the Async function to check the buffer, though. If the buffer is full, use SendMessage, and send a message you define to the program for procesing.

    -maxthecat

  6. #6
    Registered User
    Join Date
    Jul 2002
    Posts
    13
    novocaine:

    That definitely works, it just wouldn't in my case. I cant drop Unix (actually, Id rather drop MS if I was dropping, but thats my taste). This is a particular problem with peeking at the data (using recv with the MSG_PEEK command) because the data is not actually removed from the OS recieve buffer. Reading and writing data work perfectly because recv removes the bytes, allowing select calls to work correctly, and send doesnt have a problem as I can call it in a loop until all data is sent.


    maxthecat:

    Close to what Im going to end up doing. Doesnt quite work, however, because of the unix deal- async sockets are handled differently, and for design reasons I need this to be a blocking socket. Im not sure what happens in windows if async and blocking calls are mixed, which is a possibility if I went this method.


    WHat Im going to do is set up a loop in Windows that checks the amount of data in the recv buffer using ioctlsocket, and if there is less than n bytes, sleep for 100 ms. Repeat until timeout or all data is read. Unix will do a more elegant solution of changing the select low water mark so select wont return until the socket has n bytes or timesout, then replacing the old value of the watermark before exiting. With this solution the 2 versions will behave identically, although the MS code will have a coarser resolution.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Polynomials and ADT's
    By Emeighty in forum C++ Programming
    Replies: 20
    Last Post: 08-19-2008, 08:32 AM
  2. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  3. Trivial questions - what to do?
    By Aerie in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 12-26-2004, 09:44 AM
  4. Networking Questions
    By Dalren in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 07-25-2003, 03:24 PM
  5. C++: Reference Book, GUI, Networking & Beyond
    By kuphryn in forum C++ Programming
    Replies: 4
    Last Post: 11-10-2001, 08:03 PM