* gimplify.c (find_single_pointer_decl_1): New static function.
[official-gcc.git] / gcc / ada / socket.c
blob32135237b5ab8a369500221f081d624116704741
1 /****************************************************************************
2 * *
3 * GNAT COMPILER COMPONENTS *
4 * *
5 * S O C K E T *
6 * *
7 * C Implementation File *
8 * *
9 * Copyright (C) 2003-2005 Free Software Foundation, Inc. *
10 * *
11 * GNAT is free software; you can redistribute it and/or modify it under *
12 * terms of the GNU General Public License as published by the Free Soft- *
13 * ware Foundation; either version 2, or (at your option) any later ver- *
14 * sion. GNAT is distributed in the hope that it will be useful, but WITH- *
15 * OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
17 * for more details. You should have received a copy of the GNU General *
18 * Public License distributed with GNAT; see file COPYING. If not, write *
19 * to the Free Software Foundation, 51 Franklin Street, Fifth Floor, *
20 * Boston, MA 02110-1301, USA. *
21 * *
22 * As a special exception, if you link this file with other files to *
23 * produce an executable, this file does not by itself cause the resulting *
24 * executable to be covered by the GNU General Public License. This except- *
25 * ion does not however invalidate any other reasons why the executable *
26 * file might be covered by the GNU Public License. *
27 * *
28 * GNAT was originally developed by the GNAT team at New York University. *
29 * Extensive contributions were provided by Ada Core Technologies Inc. *
30 * *
31 ****************************************************************************/
33 /* This file provides a portable binding to the sockets API */
35 #include "gsocket.h"
36 /* Include all the necessary system-specific headers and define the
37 necessary macros (shared with gen-soccon). */
39 #include "raise.h"
40 /* Required for __gnat_malloc() */
42 #include <string.h>
44 extern void __gnat_disable_sigpipe (int fd);
45 extern void __gnat_free_socket_set (fd_set *);
46 extern void __gnat_last_socket_in_set (fd_set *, int *);
47 extern void __gnat_get_socket_from_set (fd_set *, int *, int *);
48 extern void __gnat_insert_socket_in_set (fd_set *, int);
49 extern int __gnat_is_socket_in_set (fd_set *, int);
50 extern fd_set *__gnat_new_socket_set (fd_set *);
51 extern void __gnat_remove_socket_from_set (fd_set *, int);
53 /* Disable the sending of SIGPIPE for writes on a broken stream */
54 void
55 __gnat_disable_sigpipe (int fd)
57 #ifdef SO_NOSIGPIPE
58 int val = 1;
59 (void) setsockopt (fd, SOL_SOCKET, SO_NOSIGPIPE, &val, sizeof val);
60 #endif
63 /* Free socket set. */
65 void
66 __gnat_free_socket_set (fd_set *set)
68 __gnat_free (set);
71 /* Find the largest socket in the socket set SET. This is needed for
72 `select'. LAST is the maximum value for the largest socket. This hint is
73 used to avoid scanning very large socket sets. On return, LAST is the
74 actual largest socket in the socket set. */
76 void
77 __gnat_last_socket_in_set (fd_set *set, int *last)
79 int s;
80 int l;
81 l = -1;
83 #ifdef WINNT
84 /* More efficient method for NT. */
85 for (s = 0; s < set->fd_count; s++)
86 if ((int) set->fd_array[s] > l)
87 l = set->fd_array[s];
89 #else
91 for (s = *last; s != -1; s--)
92 if (FD_ISSET (s, set))
94 l = s;
95 break;
97 #endif
99 *last = l;
102 /* Get last socket and remove it from the socket set SET. LAST is the
103 maximum value of the largest socket. This hint is used to avoid scanning
104 very large socket sets. On return, LAST is set to the actual largest
105 socket in the socket set. */
107 void
108 __gnat_get_socket_from_set (fd_set *set, int *last, int *socket)
110 *socket = *last;
111 FD_CLR (*socket, set);
112 __gnat_last_socket_in_set (set, last);
115 /* Insert SOCKET in the socket set SET. */
117 void
118 __gnat_insert_socket_in_set (fd_set *set, int socket)
120 FD_SET (socket, set);
123 /* Check whether a given SOCKET is in the socket set SET. */
126 __gnat_is_socket_in_set (fd_set *set, int socket)
128 return FD_ISSET (socket, set);
131 /* Allocate a new socket set and set it as empty. */
133 fd_set *
134 __gnat_new_socket_set (fd_set *set)
136 fd_set *new;
138 new = (fd_set *) __gnat_malloc (sizeof (fd_set));
140 if (set)
141 memcpy (new, set, sizeof (fd_set));
142 else
143 FD_ZERO (new);
145 return new;
148 /* Remove SOCKET from the socket set SET. */
150 void
151 __gnat_remove_socket_from_set (fd_set *set, int socket)
153 FD_CLR (socket, set);