Blame include/libssh/poll.h

Packit 6c0a39
/*
Packit 6c0a39
 * This file is part of the SSH Library
Packit 6c0a39
 *
Packit 6c0a39
 * Copyright (c) 2009 by Aris Adamantiadis
Packit 6c0a39
 *
Packit 6c0a39
 * This library is free software; you can redistribute it and/or
Packit 6c0a39
 * modify it under the terms of the GNU Lesser General Public
Packit 6c0a39
 * License as published by the Free Software Foundation; either
Packit 6c0a39
 * version 2.1 of the License, or (at your option) any later version.
Packit 6c0a39
 *
Packit 6c0a39
 * This library is distributed in the hope that it will be useful,
Packit 6c0a39
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c0a39
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c0a39
 * Lesser General Public License for more details.
Packit 6c0a39
 *
Packit 6c0a39
 * You should have received a copy of the GNU Lesser General Public
Packit 6c0a39
 * License along with this library; if not, write to the Free Software
Packit 6c0a39
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Packit 6c0a39
 */
Packit 6c0a39
Packit 6c0a39
#ifndef POLL_H_
Packit 6c0a39
#define POLL_H_
Packit 6c0a39
Packit 6c0a39
#include "config.h"
Packit 6c0a39
Packit 6c0a39
#ifdef HAVE_POLL
Packit 6c0a39
Packit 6c0a39
#include <poll.h>
Packit 6c0a39
typedef struct pollfd ssh_pollfd_t;
Packit 6c0a39
Packit 6c0a39
#else /* HAVE_POLL */
Packit 6c0a39
Packit 6c0a39
/* poll emulation support */
Packit 6c0a39
Packit 6c0a39
typedef struct ssh_pollfd_struct {
Packit 6c0a39
  socket_t fd;      /* file descriptor */
Packit 6c0a39
  short events;     /* requested events */
Packit 6c0a39
  short revents;    /* returned events */
Packit 6c0a39
} ssh_pollfd_t;
Packit 6c0a39
Packit 6c0a39
typedef unsigned long int nfds_t;
Packit 6c0a39
Packit 6c0a39
#ifdef _WIN32
Packit 6c0a39
Packit 6c0a39
#ifndef POLLRDNORM
Packit 6c0a39
#define POLLRDNORM  0x0100
Packit 6c0a39
#endif
Packit 6c0a39
#ifndef POLLRDBAND
Packit 6c0a39
#define POLLRDBAND  0x0200
Packit 6c0a39
#endif
Packit 6c0a39
#ifndef POLLIN
Packit 6c0a39
#define POLLIN      (POLLRDNORM | POLLRDBAND)
Packit 6c0a39
#endif
Packit 6c0a39
#ifndef POLLPRI
Packit 6c0a39
#define POLLPRI     0x0400
Packit 6c0a39
#endif
Packit 6c0a39
Packit 6c0a39
#ifndef POLLWRNORM
Packit 6c0a39
#define POLLWRNORM  0x0010
Packit 6c0a39
#endif
Packit 6c0a39
#ifndef POLLOUT
Packit 6c0a39
#define POLLOUT     (POLLWRNORM)
Packit 6c0a39
#endif
Packit 6c0a39
#ifndef POLLWRBAND
Packit 6c0a39
#define POLLWRBAND  0x0020
Packit 6c0a39
#endif
Packit 6c0a39
Packit 6c0a39
#ifndef POLLERR
Packit 6c0a39
#define POLLERR     0x0001
Packit 6c0a39
#endif
Packit 6c0a39
#ifndef POLLHUP
Packit 6c0a39
#define POLLHUP     0x0002
Packit 6c0a39
#endif
Packit 6c0a39
#ifndef POLLNVAL
Packit 6c0a39
#define POLLNVAL    0x0004
Packit 6c0a39
#endif
Packit 6c0a39
Packit 6c0a39
#else /* _WIN32 */
Packit 6c0a39
Packit 6c0a39
/* poll.c */
Packit 6c0a39
#ifndef POLLIN
Packit 6c0a39
#define POLLIN    0x001  /* There is data to read.  */
Packit 6c0a39
#endif
Packit 6c0a39
#ifndef POLLPRI
Packit 6c0a39
#define POLLPRI   0x002  /* There is urgent data to read.  */
Packit 6c0a39
#endif
Packit 6c0a39
#ifndef POLLOUT
Packit 6c0a39
#define POLLOUT   0x004  /* Writing now will not block.  */
Packit 6c0a39
#endif
Packit 6c0a39
Packit 6c0a39
#ifndef POLLERR
Packit 6c0a39
#define POLLERR   0x008  /* Error condition.  */
Packit 6c0a39
#endif
Packit 6c0a39
#ifndef POLLHUP
Packit 6c0a39
#define POLLHUP   0x010  /* Hung up.  */
Packit 6c0a39
#endif
Packit 6c0a39
#ifndef POLLNVAL
Packit 6c0a39
#define POLLNVAL  0x020  /* Invalid polling request.  */
Packit 6c0a39
#endif
Packit 6c0a39
Packit 6c0a39
#ifndef POLLRDNORM
Packit 6c0a39
#define POLLRDNORM  0x040 /* mapped to read fds_set */
Packit 6c0a39
#endif
Packit 6c0a39
#ifndef POLLRDBAND
Packit 6c0a39
#define POLLRDBAND  0x080 /* mapped to exception fds_set */
Packit 6c0a39
#endif
Packit 6c0a39
#ifndef POLLWRNORM
Packit 6c0a39
#define POLLWRNORM  0x100 /* mapped to write fds_set */
Packit 6c0a39
#endif
Packit 6c0a39
#ifndef POLLWRBAND
Packit 6c0a39
#define POLLWRBAND  0x200 /* mapped to write fds_set */
Packit 6c0a39
#endif
Packit 6c0a39
Packit 6c0a39
#endif /* WIN32 */
Packit 6c0a39
#endif /* HAVE_POLL */
Packit 6c0a39
Packit 6c0a39
void ssh_poll_init(void);
Packit 6c0a39
void ssh_poll_cleanup(void);
Packit 6c0a39
int ssh_poll(ssh_pollfd_t *fds, nfds_t nfds, int timeout);
Packit 6c0a39
typedef struct ssh_poll_ctx_struct *ssh_poll_ctx;
Packit 6c0a39
typedef struct ssh_poll_handle_struct *ssh_poll_handle;
Packit 6c0a39
Packit 6c0a39
/**
Packit 6c0a39
 * @brief SSH poll callback. This callback will be used when an event
Packit 6c0a39
 *                      caught on the socket.
Packit 6c0a39
 *
Packit 6c0a39
 * @param p             Poll object this callback belongs to.
Packit 6c0a39
 * @param fd            The raw socket.
Packit 6c0a39
 * @param revents       The current poll events on the socket.
Packit 6c0a39
 * @param userdata      Userdata to be passed to the callback function.
Packit 6c0a39
 *
Packit 6c0a39
 * @return              0 on success, < 0 if you removed the poll object from
Packit 6c0a39
 *                      its poll context.
Packit 6c0a39
 */
Packit 6c0a39
typedef int (*ssh_poll_callback)(ssh_poll_handle p, socket_t fd, int revents,
Packit 6c0a39
    void *userdata);
Packit 6c0a39
Packit 6c0a39
struct ssh_socket_struct;
Packit 6c0a39
Packit 6c0a39
ssh_poll_handle ssh_poll_new(socket_t fd, short events, ssh_poll_callback cb,
Packit 6c0a39
    void *userdata);
Packit 6c0a39
void ssh_poll_free(ssh_poll_handle p);
Packit 6c0a39
ssh_poll_ctx ssh_poll_get_ctx(ssh_poll_handle p);
Packit 6c0a39
short ssh_poll_get_events(ssh_poll_handle p);
Packit 6c0a39
void ssh_poll_set_events(ssh_poll_handle p, short events);
Packit 6c0a39
void ssh_poll_add_events(ssh_poll_handle p, short events);
Packit 6c0a39
void ssh_poll_remove_events(ssh_poll_handle p, short events);
Packit 6c0a39
socket_t ssh_poll_get_fd(ssh_poll_handle p);
Packit 6c0a39
void ssh_poll_set_fd(ssh_poll_handle p, socket_t fd);
Packit 6c0a39
void ssh_poll_set_callback(ssh_poll_handle p, ssh_poll_callback cb, void *userdata);
Packit 6c0a39
ssh_poll_ctx ssh_poll_ctx_new(size_t chunk_size);
Packit 6c0a39
void ssh_poll_ctx_free(ssh_poll_ctx ctx);
Packit 6c0a39
int ssh_poll_ctx_add(ssh_poll_ctx ctx, ssh_poll_handle p);
Packit 6c0a39
int ssh_poll_ctx_add_socket (ssh_poll_ctx ctx, struct ssh_socket_struct *s);
Packit 6c0a39
void ssh_poll_ctx_remove(ssh_poll_ctx ctx, ssh_poll_handle p);
Packit 6c0a39
int ssh_poll_ctx_dopoll(ssh_poll_ctx ctx, int timeout);
Packit 6c0a39
ssh_poll_ctx ssh_poll_get_default_ctx(ssh_session session);
Packit 6c0a39
int ssh_event_add_poll(ssh_event event, ssh_poll_handle p);
Packit 6c0a39
void ssh_event_remove_poll(ssh_event event, ssh_poll_handle p);
Packit 6c0a39
Packit 6c0a39
#endif /* POLL_H_ */