#ifndef SESSIONHANDLER_H
#define SESSIONHANDLER_H
#include "../util/thrpool.h"
#include "../public/nsapi.h"
#include "../util/io.h"
#include "event.h"
#include <openssl/bio.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _session_handler SessionHandler;
typedef struct _connection Connection;
struct _connection {
int fd;
struct sockaddr_in address;
HttpListener *listener;
SessionHandler *session_handler;
SSL *ssl;
WSBool ssl_accepted;
int ssl_error;
int (*read)(Connection *conn,
void *buf,
int len);
int (*write)(Connection *conn,
const void *buf,
int len);
void (*close)(Connection *conn);
};
typedef void(*enqueue_connection_f)(SessionHandler*, Connection*);
typedef void(*keep_alive_f)(SessionHandler*, Connection*);
struct _session_handler {
void(*enqueue_connection)(SessionHandler *sh, Connection *conn);
void(*keep_alive)(SessionHandler*, Connection *conn);
IOStream*(*create_iostream)(SessionHandler *sh, Connection *conn,
pool_handle_t *pool, WSBool *ssl);
};
typedef struct _basic_session_handler {
SessionHandler sh;
threadpool_t *threadpool;
} BasicSessionHandler;
typedef struct _event_session_handler {
SessionHandler sh;
EVHandler *eventhandler;
} EventSessionHandler;
int connection_read(Connection *conn,
void *buf,
int len);
int connection_write(Connection *conn,
const void *buf,
int len);
void connection_close(Connection *conn);
int connection_ssl_read(Connection *conn,
void *buf,
int len);
int connection_ssl_write(Connection *conn,
const void *buf,
int len);
void connection_ssl_close(Connection *conn);
void connection_destroy(Connection *conn);
IOStream* create_connection_iostream(
SessionHandler *sh,
Connection *conn,
pool_handle_t *pool,
WSBool *ssl);
SessionHandler* create_basic_session_handler();
void basic_enq_conn(SessionHandler *handler, Connection *conn);
void* basic_run_session(
void *data);
void basic_keep_alive(SessionHandler *handler, Connection *conn);
SessionHandler* create_event_session_handler();
void evt_enq_conn(SessionHandler *handler, Connection *conn);
int evt_request_ssl_accept(EventHandler *handler, Event *event);
int evt_request_input(EventHandler *h, Event *event);
int evt_request_finish(EventHandler *h, Event *event);
int evt_request_error(EventHandler *h, Event *event);
void evt_keep_alive(SessionHandler *handler, Connection *conn);
#ifdef __cplusplus
}
#endif
#endif