Winsock - FD_WRITE
-
Hi all, i am developing client program using WSAAsyncselect() in Winsock2. i have few queries regarding FD_WRITE. i understood that when client is connected to server. There will be FD_WRITE event posted stating that we can send the data to server. However, i want to send data to server based on some other events that the application is interested in. i am not quite sure how the FD_WRITE event will be fired when i want send data to server. here is the pseudo.
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_SOMEOTHEREVENT:
// collect the data. we need to send collected data to sever (right now data is stored in a list).
break;
case WM_SOCKET:
switch (WSAGETSELECTEVENT(lParam))
{
// how to fire this event when application wants to send data ?
case FD_WRITE:break; } break; } return 0;
}
Thanks in advance.
-
Hi all, i am developing client program using WSAAsyncselect() in Winsock2. i have few queries regarding FD_WRITE. i understood that when client is connected to server. There will be FD_WRITE event posted stating that we can send the data to server. However, i want to send data to server based on some other events that the application is interested in. i am not quite sure how the FD_WRITE event will be fired when i want send data to server. here is the pseudo.
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_SOMEOTHEREVENT:
// collect the data. we need to send collected data to sever (right now data is stored in a list).
break;
case WM_SOCKET:
switch (WSAGETSELECTEVENT(lParam))
{
// how to fire this event when application wants to send data ?
case FD_WRITE:break; } break; } return 0;
}
Thanks in advance.
Your application will receive an
FD_WRITE
event shortly after a connection is made. If your "write" operation receives aWSAEWOULDBLOCK
result, your application will find out that sends are again possible when anFD_WRITE
network event is recorded and the associated event object is set."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
Your application will receive an
FD_WRITE
event shortly after a connection is made. If your "write" operation receives aWSAEWOULDBLOCK
result, your application will find out that sends are again possible when anFD_WRITE
network event is recorded and the associated event object is set."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
Hi David, Thanks for your reply. i am sorry, i couldn't get what you mean. i understand that application will receive an FD_WRITE event shortly after a connection is made but there is no data to send at that time. here is scenario i am trying for 1) connect to server 2) Connection established - FD_WRITE event is receive. 3) there is no data to send to server 4) some other event fired (not related to socket) -- data arrived, so store the data. 5) now data is available to send to server in the above steps 4 and 5 will happen one after the another. how can i raise FD_Write event after the data is available (means step 4) ?
-
Hi David, Thanks for your reply. i am sorry, i couldn't get what you mean. i understand that application will receive an FD_WRITE event shortly after a connection is made but there is no data to send at that time. here is scenario i am trying for 1) connect to server 2) Connection established - FD_WRITE event is receive. 3) there is no data to send to server 4) some other event fired (not related to socket) -- data arrived, so store the data. 5) now data is available to send to server in the above steps 4 and 5 will happen one after the another. how can i raise FD_Write event after the data is available (means step 4) ?
Vijjuuu. wrote:
how can i raise FD_Write event after the data is available (means step 4) ?
Why would you need to raise the
FD_WRITE
event? It is sent to your application to let it know that it can now send data to the socket."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
Vijjuuu. wrote:
how can i raise FD_Write event after the data is available (means step 4) ?
Why would you need to raise the
FD_WRITE
event? It is sent to your application to let it know that it can now send data to the socket."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
Thanks again David, i understood that its lets application know that it can send data to the socket, but when there is no data to send ? and does it mean after initial FD_Write (the time after connection established) , FD_WRITE will be polled to application to let know that it can send data ? i really appreciate your patience. Thanks.
-
Thanks again David, i understood that its lets application know that it can send data to the socket, but when there is no data to send ? and does it mean after initial FD_Write (the time after connection established) , FD_WRITE will be polled to application to let know that it can send data ? i really appreciate your patience. Thanks.
Vijjuuu. wrote:
...but when there is no data to send ?
Then don't send any.
Vijjuuu. wrote:
and does it mean after initial FD_Write (the time after connection established) , FD_WRITE will be polled to application to let know that it can send data ?
Did you read the documentation that goes with that event? Your application gets the initial
FD_WRITE
event which means it can start sending data to the socket. In the event that whatever "send" function you are using returnsWSAEWOULDBLOCK
, you would then have to wait for the nextFD_WRITE
event to resume sending data to the socket."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
Hi all, i am developing client program using WSAAsyncselect() in Winsock2. i have few queries regarding FD_WRITE. i understood that when client is connected to server. There will be FD_WRITE event posted stating that we can send the data to server. However, i want to send data to server based on some other events that the application is interested in. i am not quite sure how the FD_WRITE event will be fired when i want send data to server. here is the pseudo.
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_SOMEOTHEREVENT:
// collect the data. we need to send collected data to sever (right now data is stored in a list).
break;
case WM_SOCKET:
switch (WSAGETSELECTEVENT(lParam))
{
// how to fire this event when application wants to send data ?
case FD_WRITE:break; } break; } return 0;
}
Thanks in advance.
As I understand it, the FD_WRITE message means you have a connection and room in the output buffer to accept data. After you get FD_WRITE, use send() to send data when you have it.