Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lnet / include / libcfs / darwin / darwin-tcpip.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  * Basic library routines. 
22  *
23  */
24
25 #ifndef __LIBCFS_DARWIN_TCPIP_H__
26 #define __LIBCFS_DARWIN_TCPIP_H__
27
28 #ifdef __KERNEL__
29 #include <sys/socket.h>
30
31 #ifdef __DARWIN8__
32
33 struct socket;
34
35 typedef void    (*so_upcall)(socket_t sock, void* arg, int waitf);
36
37 #define CFS_SOCK_UPCALL         0x1
38 #define CFS_SOCK_DOWN           0x2
39
40 #define CFS_SOCK_MAGIC          0xbabeface
41
42 typedef struct cfs_socket {
43         socket_t        s_so;
44         int             s_magic;
45         int             s_flags;
46         so_upcall       s_upcall;
47         void           *s_upcallarg;
48 } cfs_socket_t;
49
50
51 /* cfs_socket_t to bsd socket */
52 #define C2B_SOCK(s)             ((s)->s_so)     
53
54 static inline int get_sock_intopt(socket_t so, int opt)
55 {
56         int     val, len;
57         int     rc;
58
59         /*
60          * sock_getsockopt will take a lock(mutex) for socket,
61          * so it can be blocked. So be careful while using 
62          * them.
63          */
64         len = sizeof(val);
65         rc = sock_getsockopt(so, SOL_SOCKET, opt, &val, &len);
66         assert(rc == 0);
67         return val;
68 }
69
70 #define SOCK_ERROR(s)           get_sock_intopt(C2B_SOCK(s), SO_ERROR)        
71 /* #define SOCK_WMEM_QUEUED(s)     (0) */
72 #define SOCK_WMEM_QUEUED(s)     get_sock_intopt(C2B_SOCK(s), SO_NWRITE)
73 /* XXX Liang: no reliable way to get it in Darwin8.x */
74 #define SOCK_TEST_NOSPACE(s)    (0)
75
76 void libcfs_sock_set_cb(cfs_socket_t *sock, so_upcall callback, void *arg);
77 void libcfs_sock_reset_cb(cfs_socket_t *sock);
78
79 #else /* !__DARWIN8__ */
80
81 #define SOCK_WMEM_QUEUED(so)    ((so)->so_snd.sb_cc)
82 #define SOCK_ERROR(so)          ((so)->so_error)
83
84 #define SOCK_TEST_NOSPACE(so)   (sbspace(&(so)->so_snd) < (so)->so_snd.sb_lowat)
85
86 #endif /* !__DARWIN8__ */
87
88 #endif  /* __KERNEL END */
89
90 #endif  /* __XNU_CFS_TYPES_H__ */