00001 #ifndef PROTON_IO_H 00002 #define PROTON_IO_H 1 00003 00004 /* 00005 * 00006 * Licensed to the Apache Software Foundation (ASF) under one 00007 * or more contributor license agreements. See the NOTICE file 00008 * distributed with this work for additional information 00009 * regarding copyright ownership. The ASF licenses this file 00010 * to you under the Apache License, Version 2.0 (the 00011 * "License"); you may not use this file except in compliance 00012 * with the License. You may obtain a copy of the License at 00013 * 00014 * http://www.apache.org/licenses/LICENSE-2.0 00015 * 00016 * Unless required by applicable law or agreed to in writing, 00017 * software distributed under the License is distributed on an 00018 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 00019 * KIND, either express or implied. See the License for the 00020 * specific language governing permissions and limitations 00021 * under the License. 00022 * 00023 */ 00024 00025 #include <proton/import_export.h> 00026 #include <proton/error.h> 00027 #include <proton/type_compat.h> 00028 #include <stddef.h> 00029 00030 #ifdef __cplusplus 00031 extern "C" { 00032 #endif 00033 00034 /** 00035 * A ::pn_socket_t provides an abstract handle to an IO stream. The 00036 * pipe version is uni-directional. The network socket version is 00037 * bi-directional. Both are non-blocking. 00038 * 00039 * pn_socket_t handles from ::pn_pipe() may only be used with 00040 * ::pn_read(), ::pn_write(), ::pn_close() and pn_selector_select(). 00041 * 00042 * pn_socket_t handles from ::pn_listen(), ::pn_accept() and 00043 * ::pn_connect() must perform further IO using Proton functions. 00044 * Mixing Proton io.h functions with native IO functions on the same 00045 * handles will result in undefined behavior. 00046 * 00047 * pn_socket_t handles may only be used with a single pn_io_t during 00048 * their lifetime. 00049 */ 00050 #if defined(_WIN32) && ! defined(__CYGWIN__) 00051 #ifdef _WIN64 00052 typedef unsigned __int64 pn_socket_t; 00053 #else 00054 typedef unsigned int pn_socket_t; 00055 #endif 00056 #define PN_INVALID_SOCKET (pn_socket_t)(~0) 00057 #else 00058 typedef int pn_socket_t; 00059 #define PN_INVALID_SOCKET (-1) 00060 #endif 00061 00062 /** 00063 * A ::pn_io_t manages IO for a group of pn_socket_t handles. A 00064 * pn_io_t object may have zero or one pn_selector_t selectors 00065 * associated with it (see ::pn_io_selector()). If one is associated, 00066 * all the pn_socket_t handles managed by a pn_io_t must use that 00067 * pn_selector_t instance. 00068 * 00069 * The pn_io_t interface is single-threaded. All methods are intended 00070 * to be used by one thread at a time, except that multiple threads 00071 * may use: 00072 * 00073 * ::pn_write() 00074 * ::pn_send() 00075 * ::pn_recv() 00076 * ::pn_close() 00077 * ::pn_selector_select() 00078 * 00079 * provided at most one thread is calling ::pn_selector_select() and 00080 * the other threads are operating on separate pn_socket_t handles. 00081 */ 00082 typedef struct pn_io_t pn_io_t; 00083 00084 /** 00085 * A ::pn_selector_t provides a selection mechanism that allows 00086 * efficient monitoring of a large number of Proton connections and 00087 * listeners. 00088 * 00089 * External (non-Proton) sockets may also be monitored, either solely 00090 * for event notification (read, write, and timer) or event 00091 * notification and use with pn_io_t interfaces. 00092 */ 00093 typedef struct pn_selector_t pn_selector_t; 00094 00095 PN_EXTERN pn_io_t *pn_io(void); 00096 PN_EXTERN void pn_io_free(pn_io_t *io); 00097 PN_EXTERN pn_error_t *pn_io_error(pn_io_t *io); 00098 PN_EXTERN pn_socket_t pn_connect(pn_io_t *io, const char *host, const char *port); 00099 PN_EXTERN pn_socket_t pn_listen(pn_io_t *io, const char *host, const char *port); 00100 PN_EXTERN pn_socket_t pn_accept(pn_io_t *io, pn_socket_t socket, char *name, size_t size); 00101 PN_EXTERN void pn_close(pn_io_t *io, pn_socket_t socket); 00102 PN_EXTERN ssize_t pn_send(pn_io_t *io, pn_socket_t socket, const void *buf, size_t size); 00103 PN_EXTERN ssize_t pn_recv(pn_io_t *io, pn_socket_t socket, void *buf, size_t size); 00104 PN_EXTERN int pn_pipe(pn_io_t *io, pn_socket_t *dest); 00105 PN_EXTERN ssize_t pn_read(pn_io_t *io, pn_socket_t socket, void *buf, size_t size); 00106 PN_EXTERN ssize_t pn_write(pn_io_t *io, pn_socket_t socket, const void *buf, size_t size); 00107 PN_EXTERN bool pn_wouldblock(pn_io_t *io); 00108 PN_EXTERN pn_selector_t *pn_io_selector(pn_io_t *io); 00109 00110 #ifdef __cplusplus 00111 } 00112 #endif 00113 00114 #endif /* io.h */