if you compile 'chat_clnt.c', you will input 'gcc chat_clnt.c -D_REENTRANT -o c -lpthread'. -D_REENTRANT is automatically turn funtion designated POSIX standard to safety function about thread. -lpthread is POSIX pthread library linking option.
I will be posting Server & Client based on Thread next.
- as using Level Trigger Method, Event is continually generated while input buffer is remaining extra space.
- I give 'BUF_SIZE' 5 size in order to compare Level Trigger to Edge Trigger.
ex) Level Trigger execution screen
- Also 'select' is a Level Trigger. => received data existance check
Edge Trigger
ex) This Test transform 'EPOLLIN' into 'EPOLLIN | EPOLLET'.
- Edge Trigger Mothod can generate one event.
however, Server doesn't completely receive data which Client send.
epoll_wait() call -> fetch 5byte -> event generation wait...
◈ Use 'fcntl' to use Non-blocking I/O
- int flag=fcntl(fd, F_GETFL, 0); => fetch existing option information
- fcntl(fd, F_SETFL, flag|O_NONBLOCK); => existing option add new attribute.
Why do Non-blocking mode use?
Answer: As Edge Trigger characteristic, read & write Function Call stop executing Server for a long time.
◈ Use 'errno' which is extern valuable in the other file.
- 'errno' valuable value is different in functions whenever Error generated.
(1) What return value of read() have -1 is two meaning.
Buffer is empty or Error generated (2) EAGAIN mean that Buffer is empty because data don't exist in the buffer.
Echo Server & Client using Edge Trigger related to 'epoll'
Server provide Two or more client with service using Multiprocess.
Use 'fork()' function.
As using Multiprocess,
One server can receive messages which Clients sended.
Input/Output Routine Division
Client previously waits until Data sended or received once Data send or receive.
As using Multiprocess,
Client's parent process takes charge of 'Data Receive'.
Client's child process takes charge of 'Data Send'.
OS : Linux
=> Windows don't have function such as 'fork()'
Windows provide 'CrateProcess()' function. but It completely isn't same function.