accept.c

来自「minix操作系统最新版本(3.1.1)的源代码」· C语言 代码 · 共 66 行

C
66
字号
#include <errno.h>#include <fcntl.h>#include <stdio.h>#include <unistd.h>#include <string.h>#include <sys/ioctl.h>#include <sys/socket.h>#include <netinet/in.h>#include <net/netlib.h>#include <net/gen/in.h>#include <net/gen/tcp.h>#include <net/gen/tcp_io.h>#include <net/gen/udp.h>#include <net/gen/udp_io.h>#define DEBUG 0static int _tcp_accept(int socket, struct sockaddr *_RESTRICT address,	socklen_t *_RESTRICT address_len);int accept(int socket, struct sockaddr *_RESTRICT address,	socklen_t *_RESTRICT address_len){	int r;	r= _tcp_accept(socket, address, address_len);	return r;#if DEBUG	fprintf(stderr, "accept: not implemented for fd %d\n", socket);#endif	errno= ENOSYS;	return -1;}static int _tcp_accept(int socket, struct sockaddr *_RESTRICT address,	socklen_t *_RESTRICT address_len){	int r, s1, t_errno;	tcp_cookie_t cookie;	s1= open(TCP_DEVICE, O_RDWR);	if (s1 == -1)		return s1;	r= ioctl(s1, NWIOGTCPCOOKIE, &cookie);	if (r == -1)	{		t_errno= errno;		close(s1);		errno= t_errno;		return -1;	}	r= ioctl(socket, NWIOTCPACCEPTTO, &cookie);	if (r == -1)	{		t_errno= errno;		close(s1);		errno= t_errno;		return -1;	}	if (address != NULL)		getpeername(s1, address, address_len);	return s1;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?