I'm studying Window Sockets in C and writing a multiplexing i/o client-server application I'm tryting to deal with Standard Threads. I want to checkactivity in
stdin, stdout and stderr
but It seems I can't get how it works. Input thread it's, for example, when I use printf function or open some file (fopen,fopen_s), output - reading a message from serverby client, reading strings from fileand errorthread -just checking of errors (using fprintf(errno, "param2", param3).
What I have tried:
I want to check activity of this Threadsand I'm writing a programm just to see how it works but I met some issus.I don't understand how to check this activity (yes, maybe it soundsstupid but I really stucked with that).
I wanna do that using select() function and then FD_ZERO and FD_SET. How should I get which socket is active and which is not? How to make themactive?
Here is my "scelet" code:
<pre> #pragma comment(lib, "ws2_32.lib")
#define _WINSOCK_DEPRECATED_NO_WARNINGS
#include <winsock2.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#define BUFFERSIZE 64
#define PORT 3765
#define SERVERADDR argv[1]
int main(int argc, char *argv[])
{
struct sockaddr_in serverAddr = { 0 };
fd_set readSD;
fd_set writeSD;
fd_set errorSD;
timeval tv;
int retVal;
char msg = '1';
FD_ZERO(&readSD);
FD_ZERO(&writeSD);
FD_ZERO(&errorSD);
FD_SET(msg, &readSD);
FD_SET(msg, &writeSD);
FD_SET(msg, &errorSD);
tv.tv_sec = 5;
retVal = select(msg + 1, &readSD, &writeSD, &errorSD, &tv);
if (retVal < 0)
{
printf("Error\n");
return -1;
}
else if (retVal == 0)
{
printf("There is nobody, sorry\n");
}
else
{
int fd_isset_r = FD_ISSET(msg, &readSD);
if ((fd_isset_r)!=0)
{
printf("fd_isset_r error\n");
}
else
{
printf("readSD is %s \n", FD_ISSET(msg, &readSD) ? "ready" : "not ready");
}
int fd_isset_w = FD_ISSET(msg, &writeSD);
if ((fd_isset_w) != 0)
{
printf("fd_isset_w error\n");
}
else
{
printf("writeSD is %s\n", FD_ISSET(msg, &writeSD) ? "ready" : "not ready");
}
int fd_isset_er = FD_ISSET(msg, &errorSD);
if ((fd_isset_er) != 0)
{
printf("fd_isset_er error\n");
}
else
{
printf("errorSD is %s\n", FD_ISSET(msg, &errorSD) ? "ready" : "not ready");
}
}
system("pause");
return 0;
}
I aprreciate any advices and help. Thanks