📄 accept.c
字号:
/* * Roadrunner/pk * Copyright (C) 1989-2002 Cornfed Systems, Inc. * * The Roadrunner/pk operating system is free software; you can * redistribute and/or modify it under the terms of the GNU General * Public License, version 2, as published by the Free Software * Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the Free * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * * More information about the Roadrunner/pk operating system of * which this file is a part is available on the World-Wide Web * at: http://www.cornfed.com. * */#include <errno.h>#include <fs.h>#include <net/tcp.h>#if _DEBUG#include <stdio.h>#endif#include <stdlib.h>#include <sys/intr.h>#include <sys/socket.h>intaccept(int s, struct sockaddr *addr, int *addrlen){ socket_t socket; tcb_t tcb; if (s < 0 || s >= FILES) return EINVAL; if (filetab[s].type != FT_SOCKET) return ENOTSOCK; socket = (socket_t) filetab[s].data; if (socket->state != SS_LISTEN) {#if _DEBUG kprintf("accept: socket not listening\n");#endif return EBADF; } disable; /* Allocate and link a TCP control block to the socket */ tcb = tcb_alloc(TCPS_LISTEN); if (tcb == NULL) { enable; return EAGAIN; } socket->pcb = tcb; tcb->socket = socket; tcb->rcv_wnd = RCV_WND; /* Place the thread in socket connection queue */ current->state = PS_SOCKET; insq(current, &(socket->conn)); proc_transfer(); /* enables interrupts */ return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -