Postfix3.3.1
stream_listen.c
[詳解]
1 /*++
2 /* NAME
3 /* stream_listen 3
4 /* SUMMARY
5 /* start stream listener
6 /* SYNOPSIS
7 /* #include <listen.h>
8 /*
9 /* int stream_listen(path, backlog, block_mode)
10 /* const char *path;
11 /* int backlog;
12 /* int block_mode;
13 /*
14 /* int stream_accept(fd)
15 /* int fd;
16 /* DESCRIPTION
17 /* This module implements a substitute local IPC for systems that do
18 /* not have properly-working UNIX-domain sockets.
19 /*
20 /* stream_listen() creates a listener endpoint with the specified
21 /* permissions, and returns a file descriptor to be used for accepting
22 /* connections.
23 /*
24 /* stream_accept() accepts a connection.
25 /*
26 /* Arguments:
27 /* .IP path
28 /* Null-terminated string with connection destination.
29 /* .IP backlog
30 /* This argument exists for compatibility and is ignored.
31 /* .IP block_mode
32 /* Either NON_BLOCKING or BLOCKING. This does not affect the
33 /* mode of accepted connections.
34 /* .IP fd
35 /* File descriptor returned by stream_listen().
36 /* DIAGNOSTICS
37 /* Fatal errors: stream_listen() aborts upon any system call failure.
38 /* stream_accept() leaves all error handling up to the caller.
39 /* LICENSE
40 /* .ad
41 /* .fi
42 /* The Secure Mailer license must be distributed with this software.
43 /* AUTHOR(S)
44 /* Wietse Venema
45 /* IBM T.J. Watson Research
46 /* P.O. Box 704
47 /* Yorktown Heights, NY 10598, USA
48 /*--*/
49 
50 /* System interfaces. */
51 
52 #include <sys_defs.h>
53 
54 #ifdef STREAM_CONNECTIONS
55 
56 #include <sys/stat.h>
57 #include <unistd.h>
58 #include <errno.h>
59 #include <stropts.h>
60 #include <fcntl.h>
61 
62 #endif
63 
64 /* Utility library. */
65 
66 #include "msg.h"
67 #include "listen.h"
68 
69 /* stream_listen - create stream listener */
70 
71 int stream_listen(const char *path, int unused_backlog, int block_mode)
72 {
73 #ifdef STREAM_CONNECTIONS
74 
75  /*
76  * We can't specify a listen backlog, however, sending file descriptors
77  * across a FIFO gives us a backlog buffer of 460 on Solaris 2.4/SPARC.
78  */
79  return (fifo_listen(path, 0622, block_mode));
80 #else
81  msg_fatal("stream connections are not implemented");
82 #endif
83 }
84 
85 /* stream_accept - accept stream connection */
86 
87 int stream_accept(int fd)
88 {
89 #ifdef STREAM_CONNECTIONS
90  struct strrecvfd fdinfo;
91 
92  /*
93  * This will return EAGAIN on a non-blocking stream when someone else
94  * snatched the connection from us.
95  */
96  if (ioctl(fd, I_RECVFD, &fdinfo) < 0)
97  return (-1);
98  return (fdinfo.fd);
99 #else
100  msg_fatal("stream connections are not implemented");
101 #endif
102 }
int stream_accept(int fd)
Definition: stream_listen.c:87
int stream_listen(const char *path, int unused_backlog, int block_mode)
Definition: stream_listen.c:71
NORETURN msg_fatal(const char *fmt,...)
Definition: msg.c:249
int fifo_listen(const char *path, int permissions, int block_mode)
Definition: fifo_listen.c:52