The system calls accept (), which is a bit odd! As you can imagine, someone connects (connect () to your machine from a long distance through a port you are listening on (listen. Its connection will be added to the queue waiting for acceptance (accept. You call accept () to tell it that you have idle connections. It will return a new socket file descriptor! In this way, you have two sockets. The original one is listening to your port, and the new one is preparing to send () and receive (recv () data. This is the process of the Linux Accept function!
The code snippet of the Linux Accept function is as follows:
- struct sockaddr addrc;
- int fdc;
- socklen_t len=sizeof(struct sockaddr_in);
- fdc=accept(fds,(struct sockaddr*)&addrc,&len);
- if(fdc==-1)
- {
- fprintf(stderr,"Accept error:%s\n",strerror(errno));
- switch(errno)
- {
- case EBADF:
- printf("EBADF\n");
- break;
- case EFAULT:
- printf("EFAULT\n");
- break;
- case ENOTSOCK:
- printf("ENOTSOCK\n");
- break;
- case EOPNOTSUPP:
- printf("EOPNOTUPP\n");
- break;
- case EPERM:
- case ENOBUFS:
- case ENOMEM:
- printf("THis\n");
- case EINVAL:
- printf("EINVAL\n");
- break;
- default:
- printf("Other\n");
- }
- exit(1);
The time when the Linux Accept function runs will report Accept error: Invalid argument
EINVAL
According to my personal guess, it should be caused by the third parameter. The first parameter of accept should be okay. The first parameter output through the function is a positive value, and the previous bind and other functions have been used. No problem.
Thank you for your help.