1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-12-02 01:17:52 +03:00

Update structures name to new convention

SSH_POLL* -> ssh_poll_handle,
SSH_POLL_CTX* -> ssh_poll_ctx
This commit is contained in:
Aris Adamantiadis
2009-11-06 18:52:49 +01:00
parent fa27956daf
commit 51f1918109
2 changed files with 45 additions and 45 deletions

View File

@@ -63,8 +63,8 @@ typedef unsigned long int nfds_t;
#endif /* HAVE_POLL */ #endif /* HAVE_POLL */
int ssh_poll(ssh_pollfd_t *fds, nfds_t nfds, int timeout); int ssh_poll(ssh_pollfd_t *fds, nfds_t nfds, int timeout);
typedef struct ssh_poll_ctx SSH_POLL_CTX; typedef struct ssh_poll_ctx_struct *ssh_poll_ctx;
typedef struct ssh_poll SSH_POLL; typedef struct ssh_poll_handle_struct *ssh_poll_handle;
/** /**
* @brief SSH poll callback. * @brief SSH poll callback.
@@ -77,25 +77,25 @@ typedef struct ssh_poll SSH_POLL;
* @return 0 on success, < 0 if you removed the poll object from * @return 0 on success, < 0 if you removed the poll object from
* it's poll context. * it's poll context.
*/ */
typedef int (*ssh_poll_callback)(SSH_POLL *p, int fd, int revents, typedef int (*ssh_poll_callback)(ssh_poll_handle p, int fd, int revents,
void *userdata); void *userdata);
SSH_POLL *ssh_poll_new(socket_t fd, short events, ssh_poll_callback cb, ssh_poll_handle ssh_poll_new(socket_t fd, short events, ssh_poll_callback cb,
void *userdata); void *userdata);
void ssh_poll_free(SSH_POLL *p); void ssh_poll_free(ssh_poll_handle p);
SSH_POLL_CTX *ssh_poll_get_ctx(SSH_POLL *p); ssh_poll_ctx ssh_poll_get_ctx(ssh_poll_handle p);
short ssh_poll_get_events(SSH_POLL *p); short ssh_poll_get_events(ssh_poll_handle p);
void ssh_poll_set_events(SSH_POLL *p, short events); void ssh_poll_set_events(ssh_poll_handle p, short events);
void ssh_poll_add_events(SSH_POLL *p, short events); void ssh_poll_add_events(ssh_poll_handle p, short events);
void ssh_poll_remove_events(SSH_POLL *p, short events); void ssh_poll_remove_events(ssh_poll_handle p, short events);
socket_t ssh_poll_get_fd(SSH_POLL *p); socket_t ssh_poll_get_fd(ssh_poll_handle p);
void ssh_poll_set_callback(SSH_POLL *p, ssh_poll_callback cb, void *userdata); void ssh_poll_set_callback(ssh_poll_handle p, ssh_poll_callback cb, void *userdata);
SSH_POLL_CTX *ssh_poll_ctx_new(size_t chunk_size); ssh_poll_ctx ssh_poll_ctx_new(size_t chunk_size);
void ssh_poll_ctx_free(SSH_POLL_CTX *ctx); void ssh_poll_ctx_free(ssh_poll_ctx ctx);
int ssh_poll_ctx_add(SSH_POLL_CTX *ctx, SSH_POLL *p); int ssh_poll_ctx_add(ssh_poll_ctx ctx, ssh_poll_handle p);
void ssh_poll_ctx_remove(SSH_POLL_CTX *ctx, SSH_POLL *p); void ssh_poll_ctx_remove(ssh_poll_ctx ctx, ssh_poll_handle p);
int ssh_poll_ctx(SSH_POLL_CTX *ctx, int timeout); int ssh_poll_ctx_dopoll(ssh_poll_ctx ctx, int timeout);

View File

@@ -38,8 +38,8 @@
#define SSH_POLL_CTX_CHUNK 5 #define SSH_POLL_CTX_CHUNK 5
#endif #endif
struct ssh_poll { struct ssh_poll_handle_struct {
SSH_POLL_CTX *ctx; ssh_poll_ctx ctx;
union { union {
socket_t fd; socket_t fd;
size_t idx; size_t idx;
@@ -49,8 +49,8 @@ struct ssh_poll {
void *cb_data; void *cb_data;
}; };
struct ssh_poll_ctx { struct ssh_poll_ctx_struct {
SSH_POLL **pollptrs; ssh_poll_handle *pollptrs;
ssh_pollfd_t *pollfds; ssh_pollfd_t *pollfds;
size_t polls_allocated; size_t polls_allocated;
size_t polls_used; size_t polls_used;
@@ -245,11 +245,11 @@ int ssh_poll(ssh_pollfd_t *fds, nfds_t nfds, int timeout) {
* @return A new poll object, NULL on error * @return A new poll object, NULL on error
*/ */
SSH_POLL *ssh_poll_new(socket_t fd, short events, ssh_poll_callback cb, ssh_poll_handle ssh_poll_new(socket_t fd, short events, ssh_poll_callback cb,
void *userdata) { void *userdata) {
SSH_POLL *p; ssh_poll_handle p;
p = malloc(sizeof(SSH_POLL)); p = malloc(sizeof(struct ssh_poll_handle_struct));
if (p != NULL) { if (p != NULL) {
p->ctx = NULL; p->ctx = NULL;
p->x.fd = fd; p->x.fd = fd;
@@ -268,7 +268,7 @@ SSH_POLL *ssh_poll_new(socket_t fd, short events, ssh_poll_callback cb,
* @param p Pointer to an already allocated poll object. * @param p Pointer to an already allocated poll object.
*/ */
void ssh_poll_free(SSH_POLL *p) { void ssh_poll_free(ssh_poll_handle p) {
SAFE_FREE(p); SAFE_FREE(p);
} }
@@ -279,7 +279,7 @@ void ssh_poll_free(SSH_POLL *p) {
* *
* @return Poll context or NULL if the poll object isn't attached. * @return Poll context or NULL if the poll object isn't attached.
*/ */
SSH_POLL_CTX *ssh_poll_get_ctx(SSH_POLL *p) { ssh_poll_ctx ssh_poll_get_ctx(ssh_poll_handle p) {
return p->ctx; return p->ctx;
} }
@@ -290,7 +290,7 @@ SSH_POLL_CTX *ssh_poll_get_ctx(SSH_POLL *p) {
* *
* @return Poll events. * @return Poll events.
*/ */
short ssh_poll_get_events(SSH_POLL *p) { short ssh_poll_get_events(ssh_poll_handle p) {
return p->events; return p->events;
} }
@@ -301,7 +301,7 @@ short ssh_poll_get_events(SSH_POLL *p) {
* @param p Pointer to an already allocated poll object. * @param p Pointer to an already allocated poll object.
* @param events Poll events. * @param events Poll events.
*/ */
void ssh_poll_set_events(SSH_POLL *p, short events) { void ssh_poll_set_events(ssh_poll_handle p, short events) {
p->events = events; p->events = events;
if (p->ctx != NULL) { if (p->ctx != NULL) {
p->ctx->pollfds[p->x.idx].events = events; p->ctx->pollfds[p->x.idx].events = events;
@@ -315,7 +315,7 @@ void ssh_poll_set_events(SSH_POLL *p, short events) {
* @param p Pointer to an already allocated poll object. * @param p Pointer to an already allocated poll object.
* @param events Poll events. * @param events Poll events.
*/ */
void ssh_poll_add_events(SSH_POLL *p, short events) { void ssh_poll_add_events(ssh_poll_handle p, short events) {
ssh_poll_set_events(p, ssh_poll_get_events(p) | events); ssh_poll_set_events(p, ssh_poll_get_events(p) | events);
} }
@@ -326,7 +326,7 @@ void ssh_poll_add_events(SSH_POLL *p, short events) {
* @param p Pointer to an already allocated poll object. * @param p Pointer to an already allocated poll object.
* @param events Poll events. * @param events Poll events.
*/ */
void ssh_poll_remove_events(SSH_POLL *p, short events) { void ssh_poll_remove_events(ssh_poll_handle p, short events) {
ssh_poll_set_events(p, ssh_poll_get_events(p) & ~events); ssh_poll_set_events(p, ssh_poll_get_events(p) & ~events);
} }
@@ -338,7 +338,7 @@ void ssh_poll_remove_events(SSH_POLL *p, short events) {
* @return Raw socket. * @return Raw socket.
*/ */
socket_t ssh_poll_get_fd(SSH_POLL *p) { socket_t ssh_poll_get_fd(ssh_poll_handle p) {
if (p->ctx != NULL) { if (p->ctx != NULL) {
return p->ctx->pollfds[p->x.idx].fd; return p->ctx->pollfds[p->x.idx].fd;
} }
@@ -353,7 +353,7 @@ socket_t ssh_poll_get_fd(SSH_POLL *p) {
* @param userdata Userdata to be passed to the callback function. NULL if * @param userdata Userdata to be passed to the callback function. NULL if
* not needed. * not needed.
*/ */
void ssh_poll_set_callback(SSH_POLL *p, ssh_poll_callback cb, void *userdata) { void ssh_poll_set_callback(ssh_poll_handle p, ssh_poll_callback cb, void *userdata) {
if (cb != NULL) { if (cb != NULL) {
p->cb = cb; p->cb = cb;
p->cb_data = userdata; p->cb_data = userdata;
@@ -371,10 +371,10 @@ void ssh_poll_set_callback(SSH_POLL *p, ssh_poll_callback cb, void *userdata) {
* for the next 5. Set it to 0 if you want to use the * for the next 5. Set it to 0 if you want to use the
* library's default value. * library's default value.
*/ */
SSH_POLL_CTX *ssh_poll_ctx_new(size_t chunk_size) { ssh_poll_ctx ssh_poll_ctx_new(size_t chunk_size) {
SSH_POLL_CTX *ctx; ssh_poll_ctx ctx;
ctx = malloc(sizeof(SSH_POLL_CTX)); ctx = malloc(sizeof(struct ssh_poll_ctx_struct));
if (ctx != NULL) { if (ctx != NULL) {
if (!chunk_size) { if (!chunk_size) {
chunk_size = SSH_POLL_CTX_CHUNK; chunk_size = SSH_POLL_CTX_CHUNK;
@@ -395,13 +395,13 @@ SSH_POLL_CTX *ssh_poll_ctx_new(size_t chunk_size) {
* *
* @param ctx Pointer to an already allocated poll context. * @param ctx Pointer to an already allocated poll context.
*/ */
void ssh_poll_ctx_free(SSH_POLL_CTX *ctx) { void ssh_poll_ctx_free(ssh_poll_ctx ctx) {
if (ctx->polls_allocated > 0) { if (ctx->polls_allocated > 0) {
register size_t i, used; register size_t i, used;
used = ctx->polls_used; used = ctx->polls_used;
for (i = 0; i < used; ) { for (i = 0; i < used; ) {
SSH_POLL *p = ctx->pollptrs[i]; ssh_poll_handle p = ctx->pollptrs[i];
int fd = ctx->pollfds[i].fd; int fd = ctx->pollfds[i].fd;
/* force poll object removal */ /* force poll object removal */
@@ -419,18 +419,18 @@ void ssh_poll_ctx_free(SSH_POLL_CTX *ctx) {
SAFE_FREE(ctx); SAFE_FREE(ctx);
} }
static int ssh_poll_ctx_resize(SSH_POLL_CTX *ctx, size_t new_size) { static int ssh_poll_ctx_resize(ssh_poll_ctx ctx, size_t new_size) {
SSH_POLL **pollptrs; ssh_poll_handle *pollptrs;
ssh_pollfd_t *pollfds; ssh_pollfd_t *pollfds;
pollptrs = realloc(ctx->pollptrs, sizeof(SSH_POLL *) * new_size); pollptrs = realloc(ctx->pollptrs, sizeof(ssh_poll_handle *) * new_size);
if (pollptrs == NULL) { if (pollptrs == NULL) {
return -1; return -1;
} }
pollfds = realloc(ctx->pollfds, sizeof(ssh_pollfd_t) * new_size); pollfds = realloc(ctx->pollfds, sizeof(ssh_pollfd_t) * new_size);
if (pollfds == NULL) { if (pollfds == NULL) {
ctx->pollptrs = realloc(pollptrs, sizeof(SSH_POLL *) * ctx->polls_allocated); ctx->pollptrs = realloc(pollptrs, sizeof(ssh_poll_handle *) * ctx->polls_allocated);
return -1; return -1;
} }
@@ -449,7 +449,7 @@ static int ssh_poll_ctx_resize(SSH_POLL_CTX *ctx, size_t new_size) {
* *
* @return 0 on success, < 0 on error * @return 0 on success, < 0 on error
*/ */
int ssh_poll_ctx_add(SSH_POLL_CTX *ctx, SSH_POLL *p) { int ssh_poll_ctx_add(ssh_poll_ctx ctx, ssh_poll_handle p) {
int fd; int fd;
if (p->ctx != NULL) { if (p->ctx != NULL) {
@@ -479,7 +479,7 @@ int ssh_poll_ctx_add(SSH_POLL_CTX *ctx, SSH_POLL *p) {
* @param ctx Pointer to an already allocated poll context. * @param ctx Pointer to an already allocated poll context.
* @param p Pointer to an already allocated poll object. * @param p Pointer to an already allocated poll object.
*/ */
void ssh_poll_ctx_remove(SSH_POLL_CTX *ctx, SSH_POLL *p) { void ssh_poll_ctx_remove(ssh_poll_ctx ctx, ssh_poll_handle p) {
size_t i; size_t i;
i = p->x.idx; i = p->x.idx;
@@ -513,7 +513,7 @@ void ssh_poll_ctx_remove(SSH_POLL_CTX *ctx, SSH_POLL *p) {
* the poll() function. * the poll() function.
*/ */
int ssh_poll_ctx(SSH_POLL_CTX *ctx, int timeout) { int ssh_poll_ctx_dopoll(ssh_poll_ctx ctx, int timeout) {
int rc; int rc;
if (!ctx->polls_used) if (!ctx->polls_used)
@@ -528,7 +528,7 @@ int ssh_poll_ctx(SSH_POLL_CTX *ctx, int timeout) {
if (!ctx->pollfds[i].revents) { if (!ctx->pollfds[i].revents) {
i++; i++;
} else { } else {
SSH_POLL *p = ctx->pollptrs[i]; ssh_poll_handle p = ctx->pollptrs[i];
int fd = ctx->pollfds[i].fd; int fd = ctx->pollfds[i].fd;
int revents = ctx->pollfds[i].revents; int revents = ctx->pollfds[i].revents;