async library for manda (adaptive backend manager protocol)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

125 lines
3.6 KiB

#ifndef _LIBMANDA_LIBMANDA_H
#define _LIBMANDA_LIBMANDA_H
#include "libmanda-config.h"
#include <glib.h>
#include <sys/socket.h>
typedef enum {
MANDA_FD_READ = 1,
MANDA_FD_WRITE = 2
} manda_async_events;
typedef struct manda_async_ctrl manda_async_ctrl;
typedef struct manda_fd_watcher manda_fd_watcher;
typedef struct manda_timeout manda_timeout;
typedef struct manda_server_callbacks manda_server_callbacks;
typedef struct manda_server_connection manda_server_connection;
typedef struct manda_server manda_server;
typedef struct manda_client manda_client;
typedef void (*manda_fd_watcher_cb)(manda_fd_watcher *watcher);
typedef void (*manda_new_fd_watcher)(gpointer srv, manda_fd_watcher *watcher);
typedef void (*manda_update_fd_watcher)(gpointer srv, manda_fd_watcher *watcher);
typedef void (*manda_destroy_fd_watcher)(gpointer srv, manda_fd_watcher *watcher);
typedef void (*manda_timeout_cb)(manda_timeout *timeout);
typedef void (*manda_new_timeout)(gpointer srv, manda_timeout *timeout);
typedef void (*manda_start_timeout)(gpointer srv, manda_timeout *timeout);
typedef void (*manda_destroy_timeout)(gpointer srv, manda_timeout *timeout);
struct manda_async_ctrl {
manda_new_fd_watcher new_fd_watcher;
manda_update_fd_watcher update_fd_watcher;
manda_destroy_fd_watcher destroy_fd_watcher;
manda_new_timeout new_timeout;
manda_start_timeout start_timeout; /* one shot */
manda_destroy_timeout destroy_timeout;
};
struct manda_fd_watcher {
gpointer data; /* application data */
manda_fd_watcher_cb callback;
/* private from here */
gpointer priv;
int events; /* bitmask of manda_async_events; "update_fd_watcher" needs to check this */
int fd; /* filedescriptor; doesn't get changed after "new_fd_watcher" */
};
struct manda_timeout {
gpointer data; /* application data */
manda_timeout_cb callback;
/* private from here */
gpointer priv;
};
/* Server API */
typedef void (*manda_server_new_connection)(gpointer srv, manda_server_connection *con);
typedef void (*manda_server_closed_connection)(gpointer srv, manda_server_connection *con);
typedef void (*manda_server_acquire_backend)(gpointer srv, manda_server_connection *con, GString *name, guint16 reqid);
typedef void (*manda_server_update_backend)(gpointer srv, manda_server_connection *con, guint32 load, guint32 backends);
typedef void (*manda_server_release_backend)(gpointer srv, manda_server_connection *con, guint32 id);
struct manda_server_callbacks {
manda_server_new_connection server_new_connection;
manda_server_closed_connection server_closed_connection;
manda_server_acquire_backend server_acquire_backend;
manda_server_update_backend server_update_backend;
manda_server_release_backend server_release_backend;
};
struct manda_server_connection {
gpointer data; /* application data */
/* private from here */
gboolean delete_later;
};
struct manda_server {
gint refcount;
gpointer data; /* application data */
const manda_async_ctrl *ctrl;
const manda_server_callbacks *callbacks;
};
manda_server* manda_server_new(gpointer srv, const manda_async_ctrl *ctrl, const manda_server_callbacks *callbacks);
void manda_server_acquire(manda_server *s);
void manda_server_release(manda_server *s);
void manda_server_add_socket(manda_server *s, int fd, gpointer data);
/* Client API */
struct manda_client { /* private */
gint refcount;
gpointer data; /* application data */
const manda_async_ctrl *ctrl;
struct sockaddr *addr;
socklen_t addrlen;
};
manda_client* manda_client_new(gpointer srv, const manda_async_ctrl *ctrl, struct sockaddr *addr, socklen_t addrlen);
void manda_client_acquire(manda_client *c);
void manda_client_release(manda_client *c);
#endif