proton  0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
io.h
Go to the documentation of this file.
1 #ifndef PROTON_IO_H
2 #define PROTON_IO_H 1
3 
4 /*
5  *
6  * Licensed to the Apache Software Foundation (ASF) under one
7  * or more contributor license agreements. See the NOTICE file
8  * distributed with this work for additional information
9  * regarding copyright ownership. The ASF licenses this file
10  * to you under the Apache License, Version 2.0 (the
11  * "License"); you may not use this file except in compliance
12  * with the License. You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing,
17  * software distributed under the License is distributed on an
18  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19  * KIND, either express or implied. See the License for the
20  * specific language governing permissions and limitations
21  * under the License.
22  *
23  */
24 
25 #include <proton/import_export.h>
26 #include <proton/error.h>
27 #include <proton/type_compat.h>
28 #include <stddef.h>
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /**
35  * A ::pn_socket_t provides an abstract handle to an IO stream. The
36  * pipe version is uni-directional. The network socket version is
37  * bi-directional. Both are non-blocking.
38  *
39  * pn_socket_t handles from ::pn_pipe() may only be used with
40  * ::pn_read(), ::pn_write(), ::pn_close() and pn_selector_select().
41  *
42  * pn_socket_t handles from ::pn_listen(), ::pn_accept() and
43  * ::pn_connect() must perform further IO using Proton functions.
44  * Mixing Proton io.h functions with native IO functions on the same
45  * handles will result in undefined behavior.
46  *
47  * pn_socket_t handles may only be used with a single pn_io_t during
48  * their lifetime.
49  */
50 #if defined(_WIN32) && ! defined(__CYGWIN__)
51 #ifdef _WIN64
52 typedef unsigned __int64 pn_socket_t;
53 #else
54 typedef unsigned int pn_socket_t;
55 #endif
56 #define PN_INVALID_SOCKET (pn_socket_t)(~0)
57 #else
58 typedef int pn_socket_t;
59 #define PN_INVALID_SOCKET (-1)
60 #endif
61 
62 /**
63  * A ::pn_io_t manages IO for a group of pn_socket_t handles. A
64  * pn_io_t object may have zero or one pn_selector_t selectors
65  * associated with it (see ::pn_io_selector()). If one is associated,
66  * all the pn_socket_t handles managed by a pn_io_t must use that
67  * pn_selector_t instance.
68  *
69  * The pn_io_t interface is single-threaded. All methods are intended
70  * to be used by one thread at a time, except that multiple threads
71  * may use:
72  *
73  * ::pn_write()
74  * ::pn_send()
75  * ::pn_recv()
76  * ::pn_close()
77  * ::pn_selector_select()
78  *
79  * provided at most one thread is calling ::pn_selector_select() and
80  * the other threads are operating on separate pn_socket_t handles.
81  */
82 typedef struct pn_io_t pn_io_t;
83 
84 /**
85  * A ::pn_selector_t provides a selection mechanism that allows
86  * efficient monitoring of a large number of Proton connections and
87  * listeners.
88  *
89  * External (non-Proton) sockets may also be monitored, either solely
90  * for event notification (read, write, and timer) or event
91  * notification and use with pn_io_t interfaces.
92  */
94 
95 PN_EXTERN pn_io_t *pn_io(void);
96 PN_EXTERN void pn_io_free(pn_io_t *io);
98 PN_EXTERN pn_socket_t pn_connect(pn_io_t *io, const char *host, const char *port);
99 PN_EXTERN pn_socket_t pn_listen(pn_io_t *io, const char *host, const char *port);
100 PN_EXTERN pn_socket_t pn_accept(pn_io_t *io, pn_socket_t socket, char *name, size_t size);
101 PN_EXTERN void pn_close(pn_io_t *io, pn_socket_t socket);
102 PN_EXTERN ssize_t pn_send(pn_io_t *io, pn_socket_t socket, const void *buf, size_t size);
103 PN_EXTERN ssize_t pn_recv(pn_io_t *io, pn_socket_t socket, void *buf, size_t size);
104 PN_EXTERN int pn_pipe(pn_io_t *io, pn_socket_t *dest);
105 PN_EXTERN ssize_t pn_read(pn_io_t *io, pn_socket_t socket, void *buf, size_t size);
106 PN_EXTERN ssize_t pn_write(pn_io_t *io, pn_socket_t socket, const void *buf, size_t size);
109 
110 #ifdef __cplusplus
111 }
112 #endif
113 
114 #endif /* io.h */
struct pn_selector_t pn_selector_t
A pn_selector_t provides a selection mechanism that allows efficient monitoring of a large number of ...
Definition: io.h:93
struct pn_error_t pn_error_t
Definition: error.h:32
PN_EXTERN ssize_t pn_write(pn_io_t *io, pn_socket_t socket, const void *buf, size_t size)
struct pn_io_t pn_io_t
A pn_io_t manages IO for a group of pn_socket_t handles.
Definition: io.h:82
PN_EXTERN int pn_pipe(pn_io_t *io, pn_socket_t *dest)
PN_EXTERN pn_socket_t pn_listen(pn_io_t *io, const char *host, const char *port)
PN_EXTERN pn_socket_t pn_connect(pn_io_t *io, const char *host, const char *port)
PN_EXTERN void pn_close(pn_io_t *io, pn_socket_t socket)
PN_EXTERN pn_error_t * pn_io_error(pn_io_t *io)
PN_EXTERN void pn_io_free(pn_io_t *io)
PN_EXTERN ssize_t pn_send(pn_io_t *io, pn_socket_t socket, const void *buf, size_t size)
PN_EXTERN ssize_t pn_recv(pn_io_t *io, pn_socket_t socket, void *buf, size_t size)
#define PN_EXTERN
Definition: import_export.h:53
PN_EXTERN pn_selector_t * pn_io_selector(pn_io_t *io)
PN_EXTERN bool pn_wouldblock(pn_io_t *io)
PN_EXTERN pn_io_t * pn_io(void)
int pn_socket_t
A pn_socket_t provides an abstract handle to an IO stream.
Definition: io.h:58
PN_EXTERN pn_socket_t pn_accept(pn_io_t *io, pn_socket_t socket, char *name, size_t size)
PN_EXTERN ssize_t pn_read(pn_io_t *io, pn_socket_t socket, void *buf, size_t size)