📄 recv.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>#if _DEBUG#include <stdio.h>#endif#include <stdlib.h>#include <string.h>#include <sys/intr.h>#include <sys/socket.h>ssize_trecv(int s, void *msg, size_t len, int flags){ socket_t socket; buf_t b; char *buf; int pos, request; 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_CONNECTING && socket->state != SS_CONNECTED) return ENOTCONN; for (request = len; socket->rcv_cc < request;) { disable; /* Check connection state */ if (socket->state < SS_CONNECTED) { enable; return ENOTCONN; } else if (socket->state > SS_CONNECTED) { enable; return EINTR; } current->state = PS_SOCKET; insq(current, &(socket->rcvr)); proc_transfer(); /* enables interrupts */ } disable; for (buf = (char *) msg, pos = 0;;) { /* Take data from packet at head of receive queue */ b = socket->rcvq.h; if (b == NULL) {#if _DEBUG kprintf("recv: receive queue empty\n");#endif enable; return EINTR; } /* Check whether packet has more data than requested */ if (blen(b) >= len) { bcopy(bstart(b), buf + pos, len); bstart(b) += len; blen(b) -= len; socket->rcv_cc -= len; /* Check whether packet had exactly the amount requested */ if (blen(b) == 0) { bdeq(&(socket->rcvq)); _bfree(b); } break; } /* Packet does not contain enough to satify the entire request */ bcopy(bstart(b), buf + pos, blen(b)); len -= blen(b); pos += blen(b); socket->rcv_cc -= blen(b); bdeq(&(socket->rcvq)); _bfree(b); } enable; return request;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -