Need to see what happens: because client sends commands and server receives them but when i want the server to send commands it writes few bytes then i get this error, but this happens only after server attemp to send commands,
/* Edited/Added
BUT if client keeps sending data - server can receive them forever and nothing bad happens) maybe im forced to use select to see if fd is ready to write cause it may be reading data from fd and it didnt end and then i try to send something to this fd instead of waiting for reading to finish? Cause like i said below i only check if socket isnready to read with select. Maybe this is it??? You could tell me that if im wrong about this so i'll search for something else
*/
additionally log outputs sth like this
Received cmd from client
Received cmd from client
Received cmd from client
Sending cmd to client
Instead
Received cmd from client
Sending cmd to client
Received cmd from client
Received cmd from client
And thats unusual im a bit confused now because it may be an issue with select itself (i only check if sockets are ready to read anything) and after select i throw execute write command (and before sending i use accept() to see if there are any connections.
So maybe accept or select or whatever write read: are asynced
I always thought that if one of these functions are called and they return anything it means i can go do other things, but it finds out they do something in background(like they were creating another thread to execute),
However back to code
ProcessServerFrame is run in thread in while loop with a interval of 33 ms
void Server::ProcessFrame()
{
int selr = select (fdmax+1, &readfds, NULL, NULL, &timeoutval);
int serveri = sockfd;
if (FD_ISSET (serveri, &readfds))
{
int new_client_sock = accept (sockfd, (struct sockaddr *) &cli_addr, &clilen);
if (new_client_sock >= 0)
accept new connection here
}
//now loop through clients and check whenever they sent something
TCPWindowLayerClient * current_clientfd = clients;
while (current_clientfd != 0)
{
if (FD_ISSET (current_clientfd->sockfd, &readfds))
read_length = read_from_fd(current_clientfd->sockfd, current_clientfd->pdata, ¤t_clientfd->ppos, max_tcp_buff_size);
current_clientfd = current_clientfd->next;
}
}
void ProcessServerFrame()
{
server->ProcessFrame(); //add any pending data to clients pdata buffer stream, accept or disconnect clients and thats all
loop through clients to see if they sent any data to server ( this actually adds every cmd from client to server pending command list - so other clients will receive what one client did)
Send any pending commands to all connected clients
}
So it looks like i dont know something,
Server should behave the same on nonblocking sockets like on blocking one imo...
Code for client looks the same. Thus it only sends cmds to server
I execute select and check whenever theres something to read then i use read (theres obvious no accept function)
So the base of client and server is
Select
if(server) accept
If (theres data to be read on fd) read
Send any pending cmds to peers
That should definetly output something else than i get in log :0
cheers