2016-02-08 08:46:05 +08:00
|
|
|
/*
|
|
|
|
* libwebsockets-test-server - libwebsockets test implementation
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010-2016 Andy Green <andy@warmcat.com>
|
|
|
|
*
|
|
|
|
* This file is made available under the Creative Commons CC0 1.0
|
|
|
|
* Universal Public Domain Dedication.
|
|
|
|
*
|
|
|
|
* The person who associated a work with this deed has dedicated
|
|
|
|
* the work to the public domain by waiving all of his or her rights
|
|
|
|
* to the work worldwide under copyright law, including all related
|
|
|
|
* and neighboring rights, to the extent allowed by law. You can copy,
|
|
|
|
* modify, distribute and perform the work, even for commercial purposes,
|
|
|
|
* all without asking permission.
|
|
|
|
*
|
|
|
|
* The test apps are intended to be adapted for use in your code, which
|
|
|
|
* may be proprietary. So unlike the library itself, they are licensed
|
|
|
|
* Public Domain.
|
|
|
|
*/
|
|
|
|
|
2015-12-17 15:15:12 +08:00
|
|
|
#if defined(_WIN32) && defined(EXTERNAL_POLL)
|
|
|
|
#define WINVER 0x0600
|
|
|
|
#define _WIN32_WINNT 0x0600
|
|
|
|
#define poll(fdArray, fds, timeout) WSAPoll((LPWSAPOLLFD)(fdArray), (ULONG)(fds), (INT)(timeout))
|
|
|
|
#endif
|
|
|
|
|
2015-11-19 13:55:47 +08:00
|
|
|
#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>
|
|
|
|
#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
|
2015-12-04 11:08:32 +08:00
|
|
|
extern struct lws_pollfd *pollfds;
|
2015-11-19 13:55:47 +08:00
|
|
|
extern int *fd_lookup;
|
|
|
|
extern int count_pollfds;
|
|
|
|
#endif
|
|
|
|
extern volatile int force_exit;
|
2015-12-04 11:08:32 +08:00
|
|
|
extern struct lws_context *context;
|
2015-11-19 13:55:47 +08:00
|
|
|
extern char *resource_path;
|
|
|
|
|
2015-11-20 09:33:02 +08:00
|
|
|
extern void test_server_lock(int care);
|
|
|
|
extern void test_server_unlock(int care);
|
|
|
|
|
2015-11-19 17:14:35 +08:00
|
|
|
#ifndef __func__
|
|
|
|
#define __func__ __FUNCTION__
|
|
|
|
#endif
|
|
|
|
|
2015-11-19 13:55:47 +08:00
|
|
|
struct per_session_data__http {
|
lws_plat_fd implement platform default handlers
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>
2015-12-10 07:58:58 +08:00
|
|
|
lws_filefd_type fd;
|
2015-11-19 13:55:47 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 {
|
2015-12-04 11:08:32 +08:00
|
|
|
struct lws *wsi;
|
2015-11-19 13:55:47 +08:00
|
|
|
int ringbuffer_tail;
|
|
|
|
};
|
|
|
|
|
lws_plat_fd implement platform default handlers
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>
2015-12-10 07:58:58 +08:00
|
|
|
extern int
|
2015-12-17 07:54:44 +08:00
|
|
|
callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user,
|
|
|
|
void *in, size_t len);
|
lws_plat_fd implement platform default handlers
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>
2015-12-10 07:58:58 +08:00
|
|
|
extern int
|
2015-12-17 07:54:44 +08:00
|
|
|
callback_lws_mirror(struct lws *wsi, enum lws_callback_reasons reason,
|
|
|
|
void *user, void *in, size_t len);
|
lws_plat_fd implement platform default handlers
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>
2015-12-10 07:58:58 +08:00
|
|
|
extern int
|
2015-12-17 07:54:44 +08:00
|
|
|
callback_dumb_increment(struct lws *wsi, enum lws_callback_reasons reason,
|
|
|
|
void *user, void *in, size_t len);
|
2015-11-19 13:55:47 +08:00
|
|
|
|
|
|
|
extern void
|
2015-12-04 11:08:32 +08:00
|
|
|
dump_handshake_info(struct lws *wsi);
|