mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-16 00:00:07 +01:00

This is a rewrite of the patch from Soapyman here https://github.com/warmcat/libwebsockets/pull/363 The main changes compared to Soapyman's original patch are - There's no new stuff in the info struct user code does any overrides it may want to do explicitly after lws_context_create returns - User overrides for file ops can call through (subclass) to the original platform implementation using lws_get_fops_plat() - A typedef is provided for plat-specific fd type - Public helpers are provided to allow user code to be platform-independent about file access, using the lws platform file operations underneath: static inline lws_filefd_type lws_plat_file_open(struct lws_plat_file_ops *fops, const char *filename, unsigned long *filelen, int flags) static inline int lws_plat_file_close(struct lws_plat_file_ops *fops, lws_filefd_type fd) static inline unsigned long lws_plat_file_seek_cur(struct lws_plat_file_ops *fops, lws_filefd_type fd, long offset_from_cur_pos) static inline int lws_plat_file_read(struct lws_plat_file_ops *fops, lws_filefd_type fd, unsigned long *amount, unsigned char *buf, unsigned long len) static inline int lws_plat_file_write(struct lws_plat_file_ops *fops, lws_filefd_type fd, unsigned long *amount, unsigned char *buf, unsigned long len) There's example documentation and implementation in the test server. Signed-off-by: Andy Green <andy.green@linaro.org>
80 lines
1.7 KiB
C
80 lines
1.7 KiB
C
#include "lws_config.h"
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <getopt.h>
|
|
#include <signal.h>
|
|
#include <string.h>
|
|
#include <sys/stat.h>
|
|
#include <fcntl.h>
|
|
#include <assert.h>
|
|
|
|
#include "../lib/libwebsockets.h"
|
|
|
|
#ifdef _WIN32
|
|
#include <io.h>
|
|
#ifdef EXTERNAL_POLL
|
|
#define poll WSAPoll
|
|
#endif
|
|
#include "gettimeofday.h"
|
|
#else
|
|
#include <syslog.h>
|
|
#include <sys/time.h>
|
|
#include <unistd.h>
|
|
#endif
|
|
|
|
extern int close_testing;
|
|
extern int max_poll_elements;
|
|
|
|
#ifdef EXTERNAL_POLL
|
|
extern struct lws_pollfd *pollfds;
|
|
extern int *fd_lookup;
|
|
extern int count_pollfds;
|
|
#endif
|
|
extern volatile int force_exit;
|
|
extern struct lws_context *context;
|
|
extern char *resource_path;
|
|
|
|
extern void test_server_lock(int care);
|
|
extern void test_server_unlock(int care);
|
|
|
|
#ifndef __func__
|
|
#define __func__ __FUNCTION__
|
|
#endif
|
|
|
|
struct per_session_data__http {
|
|
lws_filefd_type fd;
|
|
};
|
|
|
|
/*
|
|
* one of these is auto-created for each connection and a pointer to the
|
|
* appropriate instance is passed to the callback in the user parameter
|
|
*
|
|
* for this example protocol we use it to individualize the count for each
|
|
* connection.
|
|
*/
|
|
|
|
struct per_session_data__dumb_increment {
|
|
int number;
|
|
};
|
|
|
|
struct per_session_data__lws_mirror {
|
|
struct lws *wsi;
|
|
int ringbuffer_tail;
|
|
};
|
|
|
|
extern int
|
|
callback_http(struct lws_context *context, struct lws *wsi,
|
|
enum lws_callback_reasons reason, void *user, void *in,
|
|
size_t len);
|
|
extern int
|
|
callback_lws_mirror(struct lws_context *context, struct lws *wsi,
|
|
enum lws_callback_reasons reason, void *user, void *in,
|
|
size_t len);
|
|
extern int
|
|
callback_dumb_increment(struct lws_context *context, struct lws *wsi,
|
|
enum lws_callback_reasons reason, void *user, void *in,
|
|
size_t len);
|
|
|
|
extern void
|
|
dump_handshake_info(struct lws *wsi);
|