|
libssh
0.7.2
|
00001 /* 00002 * This file is part of the SSH Library 00003 * 00004 * Copyright (c) 2009 by Aris Adamantiadis 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 00021 #ifndef POLL_H_ 00022 #define POLL_H_ 00023 00024 #include "config.h" 00025 00026 #ifdef HAVE_POLL 00027 00028 #include <poll.h> 00029 typedef struct pollfd ssh_pollfd_t; 00030 00031 #else /* HAVE_POLL */ 00032 00033 /* poll emulation support */ 00034 00035 typedef struct ssh_pollfd_struct { 00036 socket_t fd; /* file descriptor */ 00037 short events; /* requested events */ 00038 short revents; /* returned events */ 00039 } ssh_pollfd_t; 00040 00041 typedef unsigned long int nfds_t; 00042 00043 #ifdef _WIN32 00044 00045 #ifndef POLLRDNORM 00046 #define POLLRDNORM 0x0100 00047 #endif 00048 #ifndef POLLRDBAND 00049 #define POLLRDBAND 0x0200 00050 #endif 00051 #ifndef POLLIN 00052 #define POLLIN (POLLRDNORM | POLLRDBAND) 00053 #endif 00054 #ifndef POLLPRI 00055 #define POLLPRI 0x0400 00056 #endif 00057 00058 #ifndef POLLWRNORM 00059 #define POLLWRNORM 0x0010 00060 #endif 00061 #ifndef POLLOUT 00062 #define POLLOUT (POLLWRNORM) 00063 #endif 00064 #ifndef POLLWRBAND 00065 #define POLLWRBAND 0x0020 00066 #endif 00067 00068 #ifndef POLLERR 00069 #define POLLERR 0x0001 00070 #endif 00071 #ifndef POLLHUP 00072 #define POLLHUP 0x0002 00073 #endif 00074 #ifndef POLLNVAL 00075 #define POLLNVAL 0x0004 00076 #endif 00077 00078 #else /* _WIN32 */ 00079 00080 /* poll.c */ 00081 #ifndef POLLIN 00082 #define POLLIN 0x001 /* There is data to read. */ 00083 #endif 00084 #ifndef POLLPRI 00085 #define POLLPRI 0x002 /* There is urgent data to read. */ 00086 #endif 00087 #ifndef POLLOUT 00088 #define POLLOUT 0x004 /* Writing now will not block. */ 00089 #endif 00090 00091 #ifndef POLLERR 00092 #define POLLERR 0x008 /* Error condition. */ 00093 #endif 00094 #ifndef POLLHUP 00095 #define POLLHUP 0x010 /* Hung up. */ 00096 #endif 00097 #ifndef POLLNVAL 00098 #define POLLNVAL 0x020 /* Invalid polling request. */ 00099 #endif 00100 00101 #ifndef POLLRDNORM 00102 #define POLLRDNORM 0x040 /* mapped to read fds_set */ 00103 #endif 00104 #ifndef POLLRDBAND 00105 #define POLLRDBAND 0x080 /* mapped to exception fds_set */ 00106 #endif 00107 #ifndef POLLWRNORM 00108 #define POLLWRNORM 0x100 /* mapped to write fds_set */ 00109 #endif 00110 #ifndef POLLWRBAND 00111 #define POLLWRBAND 0x200 /* mapped to write fds_set */ 00112 #endif 00113 00114 #endif /* WIN32 */ 00115 #endif /* HAVE_POLL */ 00116 00117 void ssh_poll_init(void); 00118 void ssh_poll_cleanup(void); 00119 int ssh_poll(ssh_pollfd_t *fds, nfds_t nfds, int timeout); 00120 typedef struct ssh_poll_ctx_struct *ssh_poll_ctx; 00121 typedef struct ssh_poll_handle_struct *ssh_poll_handle; 00122 00135 typedef int (*ssh_poll_callback)(ssh_poll_handle p, socket_t fd, int revents, 00136 void *userdata); 00137 00138 struct ssh_socket_struct; 00139 00140 ssh_poll_handle ssh_poll_new(socket_t fd, short events, ssh_poll_callback cb, 00141 void *userdata); 00142 void ssh_poll_free(ssh_poll_handle p); 00143 ssh_poll_ctx ssh_poll_get_ctx(ssh_poll_handle p); 00144 short ssh_poll_get_events(ssh_poll_handle p); 00145 void ssh_poll_set_events(ssh_poll_handle p, short events); 00146 void ssh_poll_add_events(ssh_poll_handle p, short events); 00147 void ssh_poll_remove_events(ssh_poll_handle p, short events); 00148 socket_t ssh_poll_get_fd(ssh_poll_handle p); 00149 void ssh_poll_set_fd(ssh_poll_handle p, socket_t fd); 00150 void ssh_poll_set_callback(ssh_poll_handle p, ssh_poll_callback cb, void *userdata); 00151 ssh_poll_ctx ssh_poll_ctx_new(size_t chunk_size); 00152 void ssh_poll_ctx_free(ssh_poll_ctx ctx); 00153 int ssh_poll_ctx_add(ssh_poll_ctx ctx, ssh_poll_handle p); 00154 int ssh_poll_ctx_add_socket (ssh_poll_ctx ctx, struct ssh_socket_struct *s); 00155 void ssh_poll_ctx_remove(ssh_poll_ctx ctx, ssh_poll_handle p); 00156 int ssh_poll_ctx_dopoll(ssh_poll_ctx ctx, int timeout); 00157 ssh_poll_ctx ssh_poll_get_default_ctx(ssh_session session); 00158 00159 #endif /* POLL_H_ */
1.7.5.1