libssh 0.5.2
|
00001 /* 00002 * This file is part of the SSH Library 00003 * 00004 * Copyright (c) 2009 by Aris Adamantiadis 00005 * 00006 * The SSH Library is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation; either version 2.1 of the License, or (at your 00009 * option) any later version. 00010 * 00011 * The SSH Library is distributed in the hope that it will be useful, but 00012 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 00013 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00014 * License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with the SSH Library; see the file COPYING. If not, write to 00018 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 00019 * MA 02111-1307, USA. 00020 */ 00021 00022 #ifndef POLL_H_ 00023 #define POLL_H_ 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 00139 ssh_poll_handle ssh_poll_new(socket_t fd, short events, ssh_poll_callback cb, 00140 void *userdata); 00141 void ssh_poll_free(ssh_poll_handle p); 00142 ssh_poll_ctx ssh_poll_get_ctx(ssh_poll_handle p); 00143 short ssh_poll_get_events(ssh_poll_handle p); 00144 void ssh_poll_set_events(ssh_poll_handle p, short events); 00145 void ssh_poll_add_events(ssh_poll_handle p, short events); 00146 void ssh_poll_remove_events(ssh_poll_handle p, short events); 00147 socket_t ssh_poll_get_fd(ssh_poll_handle p); 00148 void ssh_poll_set_fd(ssh_poll_handle p, socket_t fd); 00149 void ssh_poll_set_callback(ssh_poll_handle p, ssh_poll_callback cb, void *userdata); 00150 ssh_poll_ctx ssh_poll_ctx_new(size_t chunk_size); 00151 void ssh_poll_ctx_free(ssh_poll_ctx ctx); 00152 int ssh_poll_ctx_add(ssh_poll_ctx ctx, ssh_poll_handle p); 00153 int ssh_poll_ctx_add_socket (ssh_poll_ctx ctx, struct ssh_socket_struct *s); 00154 void ssh_poll_ctx_remove(ssh_poll_ctx ctx, ssh_poll_handle p); 00155 int ssh_poll_ctx_dopoll(ssh_poll_ctx ctx, int timeout); 00156 ssh_poll_ctx ssh_poll_get_default_ctx(ssh_session session); 00157 00158 #endif /* POLL_H_ */