~ubuntu-branches/ubuntu/utopic/xen/utopic

« back to all changes in this revision

Viewing changes to tools/vnet/vnetd/select.h

  • Committer: Bazaar Package Importer
  • Author(s): Bastian Blank
  • Date: 2010-05-06 15:47:38 UTC
  • mto: (1.3.1) (15.1.1 sid) (4.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20100506154738-agoz0rlafrh1fnq7
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 */
 
17
#ifndef _VFC_SELECT_H_
 
18
#define _VFC_SELECT_H_
 
19
 
 
20
/** Set of file descriptors for select.
 
21
 */
 
22
typedef struct SelectSet {
 
23
    int n;
 
24
    fd_set rd, wr, er;
 
25
} SelectSet;
 
26
 
 
27
enum {
 
28
    SELECT_READ  = 1,
 
29
    SELECT_WRITE = 2,
 
30
    SELECT_ERROR = 4,
 
31
};
 
32
 
 
33
extern void SelectSet_zero(SelectSet *set);
 
34
extern void SelectSet_add(SelectSet *set, int fd, int mode);
 
35
extern void SelectSet_add_read(SelectSet *set, int fd);
 
36
extern void SelectSet_add_write(SelectSet *set, int fd);
 
37
extern void SelectSet_add_error(SelectSet *set, int fd);
 
38
extern int SelectSet_select(SelectSet *set, struct timeval *timeout);
 
39
 
 
40
static inline int SelectSet_in(SelectSet *set, int fd){
 
41
    return ((fd >= 0)
 
42
            ? ((FD_ISSET(fd, &set->rd) ? SELECT_READ : 0) |
 
43
               (FD_ISSET(fd, &set->wr) ? SELECT_WRITE : 0) |
 
44
               (FD_ISSET(fd, &set->er) ? SELECT_ERROR : 0))
 
45
            : 0);
 
46
}
 
47
 
 
48
static inline int SelectSet_in_read(SelectSet *set, int fd){
 
49
    return (fd >= 0) && FD_ISSET(fd, &set->rd);
 
50
}
 
51
 
 
52
static inline int SelectSet_in_write(SelectSet *set, int fd){
 
53
    return (fd >= 0) && FD_ISSET(fd, &set->wr);
 
54
}
 
55
 
 
56
static inline int SelectSet_in_err(SelectSet *set, int fd){
 
57
    return (fd >= 0) && FD_ISSET(fd, &set->er);
 
58
}
 
59
 
 
60
#endif /* ! _VFC_SELECT_H_ */