Winsock send buffer
How do I find out how big the send buffer is, and how full it is? I''m using winsock and sock streams.
For a good time hit Alt-F4! Go ahead try it, all the cool people are doing it.
You can get the send buffer size by doing a getsockopt() on the network socket file descriptor.
int nBufferSize;
int nSize = sizeof(nBufferSize);
getsockopt(sockfd, SOL_SOCKET, SO_SNDBUFF, &nBufferSize, &nSize);
The answer will be put into the ''nBufferSize'' variable as an integer.
I didn''t compile this, just build it out of the MSDN prototype (I''ve used it before though). You want to look into setsockopt() and getsockopt() for making tweaks upon the socket descriptor. It is very nice to see all the options you can do. I believe the setsockopt() call using the SO_SNDBUFF allows you to alter the send buffer size.
To get the amount of data pending on a socket you can use the "windows" version of ioctl() called ioctlsocket(). The prototype suggests something like so (in the MSDN):
unsigned long PendingData;
ioctlsocket(sockfd, FIONREAD, &PendingData);
The ''PendingData'' value will tell you how much data is on the socket, which you could then do a read() or recv() to obtain. Note: I used this at work (on a different OS) and I noticed that checking for pending data on a UDP socket always gives me the full recv buffer size (because UDP only has one packet, and its always all counted for whatever reason). So its kinda "iffy" when it comes to UDP datagrams.
Hope that helps you out a little. I suggest looking up the values for yourself in the MSDN to make sure you know everything you need to about the routines.
CodeMonkey
int nBufferSize;
int nSize = sizeof(nBufferSize);
getsockopt(sockfd, SOL_SOCKET, SO_SNDBUFF, &nBufferSize, &nSize);
The answer will be put into the ''nBufferSize'' variable as an integer.
I didn''t compile this, just build it out of the MSDN prototype (I''ve used it before though). You want to look into setsockopt() and getsockopt() for making tweaks upon the socket descriptor. It is very nice to see all the options you can do. I believe the setsockopt() call using the SO_SNDBUFF allows you to alter the send buffer size.
To get the amount of data pending on a socket you can use the "windows" version of ioctl() called ioctlsocket(). The prototype suggests something like so (in the MSDN):
unsigned long PendingData;
ioctlsocket(sockfd, FIONREAD, &PendingData);
The ''PendingData'' value will tell you how much data is on the socket, which you could then do a read() or recv() to obtain. Note: I used this at work (on a different OS) and I noticed that checking for pending data on a UDP socket always gives me the full recv buffer size (because UDP only has one packet, and its always all counted for whatever reason). So its kinda "iffy" when it comes to UDP datagrams.
Hope that helps you out a little. I suggest looking up the values for yourself in the MSDN to make sure you know everything you need to about the routines.
CodeMonkey
CODE Monkey
okay, that helps on how big the send buffer is. By the way what version of winsock does that take? 1.1? 2?
So how do I find out how full the send buffer is? Like how much data is waiting to be sent.
So how do I find out how full the send buffer is? Like how much data is waiting to be sent.
For a good time hit Alt-F4! Go ahead try it, all the cool people are doing it.
Ooops, sorry about that, I gave you the routine for getting data pending on the socket which is ready to read. However, not ready to send
I do not believe you can find out how full the send buffer is, because the send()/write() call does not return until the data has been successfully sent. At least that is how it "appears", but I am not sure what the implementation is for how datagrams are send out the NIC card. Usually that is not a required thing to know because if you do a send() and the call returns then you''re pretty much assured that the data has been sent out the NIC card and onto the network (providing all went well).
Usually the only area is a concern is for incoming data, which you can use the ioctlsocket() routines with.
The routines I''ve mentioned are not "winsock" version dependant, and are found in all Berkely socket implementations (but the routine names may be different).
Hope that helps.
Derrick
I do not believe you can find out how full the send buffer is, because the send()/write() call does not return until the data has been successfully sent. At least that is how it "appears", but I am not sure what the implementation is for how datagrams are send out the NIC card. Usually that is not a required thing to know because if you do a send() and the call returns then you''re pretty much assured that the data has been sent out the NIC card and onto the network (providing all went well).
Usually the only area is a concern is for incoming data, which you can use the ioctlsocket() routines with.
The routines I''ve mentioned are not "winsock" version dependant, and are found in all Berkely socket implementations (but the routine names may be different).
Hope that helps.
Derrick
CODE Monkey
The send function returns when the data is put in the send buffer. If the send buffer is full the function blocks. If the socket is nonblocking it returns WSAEWOULDBLOCK.
quote:
From msdn
The successful completion of a send does not indicate that the data was successfully delivered.
For a good time hit Alt-F4! Go ahead try it, all the cool people are doing it.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement