ia64/xen-unstable

view tools/vnet/vnetd/select.c @ 8740:3d7ea7972b39

Update patches for linux 2.6.15.

Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Thu Feb 02 17:16:00 2006 +0000 (2006-02-02)
parents 0a4b76b6b5a0
children 71b0f00f6344
line source
1 /*
2 * Copyright (C) 2003 - 2004 Mike Wray <mike.wray@hp.com>.
3 *
4 * This library is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as
6 * published by the Free Software Foundation; either version 2.1 of the
7 * License, or (at your option) any later version. This library is
8 * distributed in the hope that it will be useful, but WITHOUT ANY
9 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE.
11 * See the GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this library; if not, write to the Free Software Foundation,
15 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
18 #include <stdlib.h>
19 #include <errno.h>
20 #include <unistd.h>
22 #include "select.h"
24 /** Zero all the file descriptor sets.
25 *
26 * @param set select set
27 * @param fd file descriptor
28 * @return 0 on success, -1 otherwise
29 */
30 void SelectSet_zero(SelectSet *set){
31 set->n = 0;
32 FD_ZERO(&set->rd);
33 FD_ZERO(&set->wr);
34 FD_ZERO(&set->er);
35 }
37 /** Add a file descriptor to the write set.
38 *
39 * @param set select set
40 * @param fd file descriptor
41 * @return 0 on success, -1 otherwise
42 */
43 void SelectSet_add_read(SelectSet *set, int fd){
44 FD_SET(fd, &set->rd);
45 if(fd > set->n) set->n = fd;
46 }
48 /** Add a file descriptor to the write set.
49 *
50 * @param set select set
51 * @param fd file descriptor
52 * @return 0 on success, -1 otherwise
53 */
54 void SelectSet_add_write(SelectSet *set, int fd){
55 FD_SET(fd, &set->wr);
56 if(fd > set->n) set->n = fd;
57 }
59 /** Select on file descriptors.
60 *
61 * @param set select set
62 * @param timeout timeout (may be NULL for no timeout)
63 * @return 0 on success, -1 otherwise
64 */
65 int SelectSet_select(SelectSet *set, struct timeval *timeout){
66 return select(set->n+1, &set->rd, &set->wr, &set->er, timeout);
67 }