file handling apis
```
- static inline lws_filefd_type
- `lws_plat_file_open`(struct lws *wsi, const char *filename, unsigned long *filelen, int flags)
-
+ static inline lws_fop_fd_t
+ `lws_plat_file_open`(struct lws_plat_file_ops *fops, const char *filename,
+ lws_filepos_t *filelen, lws_fop_flags_t *flags)
static inline int
- `lws_plat_file_close`(struct lws *wsi, lws_filefd_type fd)
+ `lws_plat_file_close`(lws_fop_fd_t fop_fd)
static inline unsigned long
- `lws_plat_file_seek_cur`(struct lws *wsi, lws_filefd_type fd, long offset_from_cur_pos)
+ `lws_plat_file_seek_cur`(lws_fop_fd_t fop_fd, lws_fileofs_t offset)
static inline int
- `lws_plat_file_read`(struct lws *wsi, lws_filefd_type fd, unsigned long *amount, unsigned char *buf, unsigned long len)
+ `lws_plat_file_read`(lws_fop_fd_t fop_fd, lws_filepos_t *amount,
+ uint8_t *buf, lws_filepos_t len)
static inline int
- `lws_plat_file_write`(struct lws *wsi, lws_filefd_type fd, unsigned long *amount, unsigned char *buf, unsigned long len)
+ `lws_plat_file_write`(lws_fop_fd_t fop_fd, lws_filepos_t *amount,
+ uint8_t *buf, lws_filepos_t len )
```
The user code can also override or subclass the file operations, to either
wrap or replace them. An example is shown in test server.
+### Changes from v2.1 and before fops
+
+There are three changes:
+
+1) Pre-2.2 fops directly used platform file descriptors. Current fops returns and accepts a wrapper type lws_fop_fd_t which is a pointer to a malloc'd struct containing information specific to the filesystem implementation.
+
+2) Pre-2.2 fops bound the fops to a wsi. This is completely removed, you just give a pointer to the fops struct that applies to this file when you open it. Afterwards, the operations in the fops just need the lws_fop_fd_t returned from the open.
+
+3) Everything is wrapped in typedefs. See lws-plat-unix.c for examples of how to implement.
+
@section ecdh ECDH Support
ECDH Certs are now supported. Enable the CMake option
if (wsi->state == LWSS_HTTP2_ESTABLISHED_PRE_SETTINGS) {
wsi->state = LWSS_HTTP2_ESTABLISHED;
- wsi->u.http.fd = LWS_INVALID_FILE;
+ wsi->u.http.fop_fd = NULL;
if (lws_is_ssl(lws_http2_get_network_wsi(wsi))) {
lwsl_info("skipping nonexistent ssl upgrade headers\n");
}
if (wsi->mode == LWSCM_HTTP_SERVING_ACCEPTED &&
- wsi->u.http.fd != LWS_INVALID_FILE) {
- lws_plat_file_close(wsi, wsi->u.http.fd);
- wsi->u.http.fd = LWS_INVALID_FILE;
+ wsi->u.http.fop_fd != NULL) {
+ lws_plat_file_close(wsi->u.http.fop_fd);
+ wsi->u.http.fop_fd = NULL;
wsi->vhost->protocols->callback(wsi,
LWS_CALLBACK_CLOSED_HTTP, wsi->user_space, NULL, 0);
wsi->told_user_closed = 1;
#define LWS_FOP_FLAG_COMPR_ACCEPTABLE_GZIP (1 << 24)
#define LWS_FOP_FLAG_COMPR_IS_GZIP (1 << 25)
+struct lws_plat_file_ops;
+struct lws_fop_fd {
+ lws_filefd_type fd;
+ struct lws_plat_file_ops *fops;
+ void *filesystem_priv;
+};
+#if defined(WIN32) || defined(_WIN32)
+/* ... */
+typedef SSIZE_T ssize_t;
+/* !!! >:-[ */
+typedef unsigned __int32 uint32_t;
+typedef unsigned __int8 uint8_t;
+#endif
+typedef struct lws_fop_fd *lws_fop_fd_t;
+typedef size_t lws_filepos_t;
+typedef ssize_t lws_fileofs_t;
+typedef uint32_t lws_fop_flags_t;
+
struct lws_plat_file_ops {
- lws_filefd_type (*LWS_FOP_OPEN)(struct lws *wsi, const char *filename,
- unsigned long *filelen, int *flags);
+ lws_fop_fd_t (*LWS_FOP_OPEN)(struct lws_plat_file_ops *fops,
+ const char *filename,
+ lws_filepos_t *filelen,
+ lws_fop_flags_t *flags);
/**< Open file (always binary access if plat supports it)
* filelen is filled on exit to be the length of the file
* *flags & LWS_FOP_FLAGS_MASK should be set to O_RDONLY or O_RDWR.
* gzip-compressed, then the open handler should OR
* LWS_FOP_FLAG_COMPR_IS_GZIP on to *flags before returning.
*/
- int (*LWS_FOP_CLOSE)(struct lws *wsi, lws_filefd_type fd);
+ int (*LWS_FOP_CLOSE)(lws_fop_fd_t fop_fd);
/**< close file */
- unsigned long (*LWS_FOP_SEEK_CUR)(struct lws *wsi, lws_filefd_type fd,
- long offset_from_cur_pos);
+ lws_fileofs_t (*LWS_FOP_SEEK_CUR)(lws_fop_fd_t fop_fd,
+ lws_fileofs_t offset_from_cur_pos);
/**< seek from current position */
- int (*LWS_FOP_READ)(struct lws *wsi, lws_filefd_type fd,
- unsigned long *amount, unsigned char *buf,
- unsigned long len);
+ int (*LWS_FOP_READ)(lws_fop_fd_t fop_fd, lws_filepos_t *amount,
+ uint8_t *buf, lws_filepos_t len);
/**< Read from file, on exit *amount is set to amount actually read */
- int (*LWS_FOP_WRITE)(struct lws *wsi, lws_filefd_type fd,
- unsigned long *amount, unsigned char *buf,
- unsigned long len);
+ int (*LWS_FOP_WRITE)(lws_fop_fd_t fop_fd, lws_filepos_t *amount,
+ uint8_t *buf, lws_filepos_t len);
/**< Write to file, on exit *amount is set to amount actually written */
/* Add new things just above here ---^
/**
* lws_plat_file_open() - file open operations
*
- * \param wsi: connection doing the opening
+ * \param fops: file ops struct that applies to this descriptor
* \param filename: filename to open
* \param filelen: length of file (filled in by call)
- * \param flags: open flags
+ * \param flags: pointer to open flags
+ *
+ * returns semi-opaque handle
*/
-static LWS_INLINE lws_filefd_type LWS_WARN_UNUSED_RESULT
-lws_plat_file_open(struct lws *wsi, const char *filename,
- unsigned long *filelen, int *flags)
+static LWS_INLINE lws_fop_fd_t LWS_WARN_UNUSED_RESULT
+lws_plat_file_open(struct lws_plat_file_ops *fops, const char *filename,
+ lws_filepos_t *filelen, lws_fop_flags_t *flags)
{
- return lws_get_fops(lws_get_context(wsi))->LWS_FOP_OPEN(wsi, filename,
- filelen, flags);
+ return fops->LWS_FOP_OPEN(fops, filename, filelen, flags);
}
/**
* lws_plat_file_close() - close file
*
- * \param wsi: connection opened by
- * \param fd: file descriptor
+ * \param fop_fd: file handle to close
*/
static LWS_INLINE int
-lws_plat_file_close(struct lws *wsi, lws_filefd_type fd)
+lws_plat_file_close(lws_fop_fd_t fop_fd)
{
- return lws_get_fops(lws_get_context(wsi))->LWS_FOP_CLOSE(wsi, fd);
+ return fop_fd->fops->LWS_FOP_CLOSE(fop_fd);
}
/**
* lws_plat_file_seek_cur() - close file
*
- * \param wsi: connection opened by
- * \param fd: file descriptor
+ *
+ * \param fop_fd: file handle
* \param offset: position to seek to
*/
-static LWS_INLINE unsigned long
-lws_plat_file_seek_cur(struct lws *wsi, lws_filefd_type fd, long offset)
+static LWS_INLINE lws_fileofs_t
+lws_plat_file_seek_cur(lws_fop_fd_t fop_fd, lws_fileofs_t offset)
{
- return lws_get_fops(lws_get_context(wsi))->LWS_FOP_SEEK_CUR(wsi,
- fd, offset);
+ return fop_fd->fops->LWS_FOP_SEEK_CUR(fop_fd, offset);
}
/**
* lws_plat_file_read() - read from file
*
- * \param wsi: connection opened by
- * \param fd: file descriptor
+ * \param fop_fd: file handle
* \param amount: how much to read (rewritten by call)
* \param buf: buffer to write to
* \param len: max length
*/
static LWS_INLINE int LWS_WARN_UNUSED_RESULT
-lws_plat_file_read(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
- unsigned char *buf, unsigned long len)
+lws_plat_file_read(lws_fop_fd_t fop_fd, lws_filepos_t *amount,
+ uint8_t *buf, lws_filepos_t len)
{
- return lws_get_fops(lws_get_context(wsi))->LWS_FOP_READ(wsi, fd,
- amount, buf, len);
+ return fop_fd->fops->LWS_FOP_READ(fop_fd, amount, buf, len);
}
/**
* lws_plat_file_write() - write from file
*
- * \param wsi: connection opened by
- * \param fd: file descriptor
+ * \param fop_fd: file handle
* \param amount: how much to write (rewritten by call)
* \param buf: buffer to read from
* \param len: max length
*/
static LWS_INLINE int LWS_WARN_UNUSED_RESULT
-lws_plat_file_write(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
- unsigned char *buf, unsigned long len)
+lws_plat_file_write(lws_fop_fd_t fop_fd, lws_filepos_t *amount,
+ uint8_t *buf, lws_filepos_t len)
{
- return lws_get_fops(lws_get_context(wsi))->LWS_FOP_WRITE(wsi, fd,
- amount, buf, len);
+ return fop_fd->fops->LWS_FOP_WRITE(fop_fd, amount, buf, len);
}
//@}
return inet_ntop(af, src, dst, cnt);
}
-static lws_filefd_type
-_lws_plat_file_open(struct lws *wsi, const char *filename,
- unsigned long *filelen, int *flags)
+static lws_fop_fd_t
+_lws_plat_file_open(struct lws_plat_file_ops *fops, const char *filename,
+ lws_filepos_t *filelen, lws_fop_flags_t *flags)
{
struct stat stat_buf;
-
+ lws_fop_fd_t fop_fd;
int ret = open(filename, *flags, 0664);
if (ret < 0)
- return LWS_INVALID_FILE;
+ return NULL;
+
+ if (fstat(ret, &stat_buf) < 0)
+
+ fop_fd = malloc(sizeof(*fop_fd));
+ if (!fop_fd)
+ goto bail;
+
+ fop_fd->fops = fops;
+ fop_fd->fd = ret;
+ fop_fd->filesystem_priv = NULL; /* we don't use it */
- if (fstat(ret, &stat_buf) < 0) {
- close(ret);
- return LWS_INVALID_FILE;
- }
*filelen = stat_buf.st_size;
- return (lws_filefd_type)ret;
+
+ return fop_fd;
+
+bail:
+ close(ret);
+
+ return NULL;
}
static int
-_lws_plat_file_close(struct lws *wsi, lws_filefd_type fd)
+_lws_plat_file_close(lws_fop_fd_t fops_fd)
{
- return close((int)fd);
+ int fd = fops_fd->fd;
+
+ free(fd);
+
+ return close(fd);
}
-unsigned long
-_lws_plat_file_seek_cur(struct lws *wsi, lws_filefd_type fd, long offset)
+lws_fileofs_t
+_lws_plat_file_seek_cur(lws_fop_fd_t fops_fd, lws_fileofs_t offset)
{
- return lseek((int)fd, offset, SEEK_CUR);
+ return lseek(fops_fd->fd, offset, SEEK_CUR);
}
static int
-_lws_plat_file_read(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
- unsigned char *buf, unsigned long len)
+_lws_plat_file_read(lws_fop_fd_t fops_fd, lws_filepos_t *amount,
+ uint8_t *buf, lws_filepos_t len)
{
long n;
- n = read((int)fd, buf, len);
+ n = read(fops_fd->fd, buf, len);
if (n == -1) {
*amount = 0;
return -1;
}
static int
-_lws_plat_file_write(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
- unsigned char *buf, unsigned long len)
+_lws_plat_file_write(lws_fop_fd_t fops_fd, lws_filepos_t *amount,
+ uint8_t *buf, lws_filepos_t len)
{
long n;
- n = write((int)fd, buf, len);
+ n = write(fops_fd->fd, buf, len);
if (n == -1) {
*amount = 0;
return -1;
return "lws_plat_inet_ntop";
}
-static lws_filefd_type
-_lws_plat_file_open(struct lws *wsi, const char *filename,
- unsigned long *filelen, int *flags)
+static lws_fop_fd_t
+_lws_plat_file_open(lws_plat_file_open(struct lws_plat_file_ops *fops,
+ const char *filename, lws_filepos_t *filelen,
+ lws_fop_flags_t *flags)
{
- return 0;
+ return NULL;
}
static int
-_lws_plat_file_close(struct lws *wsi, lws_filefd_type fd)
+_lws_plat_file_close(lws_fop_fd_t fop_fd)
{
return 0;
}
-unsigned long
-_lws_plat_file_seek_cur(struct lws *wsi, lws_filefd_type fd, long offset)
+unsigned lws_fileofs_t
+_lws_plat_file_seek_cur(lws_fop_fd_t fop_fd, lws_fileofs_t offset)
{
return 0;
}
static int
-_lws_plat_file_read(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
- unsigned char *buf, unsigned long len)
+_lws_plat_file_read(lws_fop_fd_t fop_fd, lws_filepos_t *amount,
+ uint8_t *buf, lws_filepos_t len)
{
return 0;
}
static int
-_lws_plat_file_write(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
- unsigned char *buf, unsigned long len)
+_lws_plat_file_write(lws_fop_fd_t fop_fd, lws_filepos_t *amount,
+ uint8_t *buf, lws_filepos_t len)
{
return 0;
return inet_ntop(af, src, dst, cnt);
}
-static lws_filefd_type
-_lws_plat_file_open(struct lws *wsi, const char *filename,
- unsigned long *filelen, int *flags)
+// lws_get_fops(lws_get_context(wsi))
+
+static lws_fop_fd_t
+_lws_plat_file_open(struct lws_plat_file_ops *fops, const char *filename,
+ lws_filepos_t *filelen, lws_fop_flags_t *flags)
{
struct stat stat_buf;
int ret = open(filename, (*flags) & LWS_FOP_FLAGS_MASK, 0664);
+ lws_fop_fd_t fop_fd;
if (ret < 0)
- return LWS_INVALID_FILE;
+ return NULL;
- if (fstat(ret, &stat_buf) < 0) {
- close(ret);
- return LWS_INVALID_FILE;
- }
+ if (fstat(ret, &stat_buf) < 0)
+ goto bail;
+
+ fop_fd = malloc(sizeof(*fop_fd));
+ if (!fop_fd)
+ goto bail;
+
+ fop_fd->fops = fops;
+ fop_fd->fd = ret;
+ fop_fd->filesystem_priv = NULL; /* we don't use it */
*filelen = stat_buf.st_size;
- return ret;
+
+ return fop_fd;
+
+bail:
+ close(ret);
+ return NULL;
}
static int
-_lws_plat_file_close(struct lws *wsi, lws_filefd_type fd)
+_lws_plat_file_close(lws_fop_fd_t fop_fd)
{
+ int fd = fop_fd->fd;
+
+ free(fop_fd);
return close(fd);
}
-unsigned long
-_lws_plat_file_seek_cur(struct lws *wsi, lws_filefd_type fd, long offset)
+lws_fileofs_t
+_lws_plat_file_seek_cur(lws_fop_fd_t fop_fd, lws_fileofs_t offset)
{
- return lseek(fd, offset, SEEK_CUR);
+ return lseek(fop_fd->fd, offset, SEEK_CUR);
}
static int
-_lws_plat_file_read(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
- unsigned char *buf, unsigned long len)
+_lws_plat_file_read(lws_fop_fd_t fop_fd, lws_filepos_t *amount,
+ uint8_t *buf, lws_filepos_t len)
{
long n;
- n = read((int)fd, buf, len);
+ n = read((int)fop_fd->fd, buf, len);
if (n == -1) {
*amount = 0;
return -1;
}
static int
-_lws_plat_file_write(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
- unsigned char *buf, unsigned long len)
+_lws_plat_file_write(lws_fop_fd_t fop_fd, lws_filepos_t *amount,
+ uint8_t *buf, lws_filepos_t len)
{
long n;
- n = write((int)fd, buf, len);
+ n = write((int)fop_fd->fd, buf, len);
if (n == -1) {
*amount = 0;
return -1;
return ok ? dst : NULL;
}
-static lws_filefd_type
-_lws_plat_file_open(struct lws *wsi, const char *filename,
- unsigned long *filelen, int *flags)
+static lws_fop_fd_t
+_lws_plat_file_open(struct lws_plat_file_ops *fops, const char *filename,
+ lws_filepos_t *filelen, lws_fop_flags_t *flags)
{
HANDLE ret;
WCHAR buf[MAX_PATH];
+ lws_fop_fd_t fop_fd;
- (void)wsi;
MultiByteToWideChar(CP_UTF8, 0, filename, -1, buf, ARRAY_SIZE(buf));
if (((*flags) & 7) == _O_RDONLY) {
ret = CreateFileW(buf, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
} else {
lwsl_err("%s: open for write not implemented\n", __func__);
- *filelen = 0;
- return LWS_INVALID_FILE;
+ goto bail;
}
- if (ret != LWS_INVALID_FILE)
- *filelen = GetFileSize(ret, NULL);
+ if (ret == LWS_INVALID_FILE)
+ goto bail;
- return ret;
+ fop_fd = malloc(sizeof(*fop_fd));
+ if (!fop_fd)
+ goto bail;
+
+ fop_fd->fops = fops;
+ fop_fd->fd = ret;
+ fop_fd->filesystem_priv = NULL; /* we don't use it */
+
+ *filelen = GetFileSize(ret, NULL);
+
+ return fop_fd;
+
+bail:
+ *filelen = 0;
+ return NULL;
}
static int
-_lws_plat_file_close(struct lws *wsi, lws_filefd_type fd)
+_lws_plat_file_close(lws_fop_fd_t fop_fd)
{
- (void)wsi;
+ HANDLE fd = fop_fd->fd;
+
+ free(fop_fd);
CloseHandle((HANDLE)fd);
return 0;
}
-static unsigned long
-_lws_plat_file_seek_cur(struct lws *wsi, lws_filefd_type fd, long offset)
+static lws_fileofs_t
+_lws_plat_file_seek_cur(lws_fop_fd_t fop_fd, lws_fileofs_t offset)
{
- (void)wsi;
-
- return SetFilePointer((HANDLE)fd, offset, NULL, FILE_CURRENT);
+ return SetFilePointer((HANDLE)fop_fd->fd, offset, NULL, FILE_CURRENT);
}
static int
-_lws_plat_file_read(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
- unsigned char* buf, unsigned long len)
+_lws_plat_file_read(lws_fop_fd_t fop_fd, lws_filepos_t *amount,
+ uint8_t *buf, lws_filepos_t len)
{
DWORD _amount;
- if (!ReadFile((HANDLE)fd, buf, (DWORD)len, &_amount, NULL)) {
+ if (!ReadFile((HANDLE)fop_fd->fd, buf, (DWORD)len, &_amount, NULL)) {
*amount = 0;
return 1;
}
static int
-_lws_plat_file_write(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
- unsigned char* buf, unsigned long len)
+_lws_plat_file_write(lws_fop_fd_t fop_fd, lws_filepos_t *amount,
+ uint8_t* buf, lws_filepos_t len)
{
- (void)wsi;
- (void)fd;
+ (void)fop_fd;
(void)amount;
(void)buf;
(void)len;
struct lws_context *context = wsi->context;
struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi];
struct lws_process_html_args args;
- unsigned long amount, poss;
+ lws_filepos_t amount, poss;
unsigned char *p;
#if defined(LWS_WITH_RANGES)
unsigned char finished = 0;
lwsl_notice("%s: doing range start %llu\n", __func__, wsi->u.http.range.start);
- if ((long)lws_plat_file_seek_cur(wsi, wsi->u.http.fd,
+ if ((long)lws_plat_file_seek_cur(wsi->u.http.fop_fd,
wsi->u.http.range.start -
wsi->u.http.filepos) < 0)
return -1;
poss -= 10 + 128;
}
- if (lws_plat_file_read(wsi, wsi->u.http.fd, &amount, p, poss) < 0)
+ if (lws_plat_file_read(wsi->u.http.fop_fd, &amount, p, poss) < 0)
return -1; /* caller will close */
//lwsl_notice("amount %ld\n", amount);
if (m != n) {
/* adjust for what was not sent */
- if (lws_plat_file_seek_cur(wsi, wsi->u.http.fd,
+ if (lws_plat_file_seek_cur(wsi->u.http.fop_fd,
m - n) ==
(unsigned long)-1)
return -1;
{
wsi->state = LWSS_HTTP;
/* we might be in keepalive, so close it off here */
- lws_plat_file_close(wsi, wsi->u.http.fd);
- wsi->u.http.fd = LWS_INVALID_FILE;
+ lws_plat_file_close(wsi->u.http.fop_fd);
+ wsi->u.http.fop_fd = NULL;
lwsl_debug("file completed\n");
#endif
unsigned int preamble_rx_len;
struct lws *new_wsi_list;
- unsigned long filepos;
- unsigned long filelen;
- lws_filefd_type fd;
+ lws_filepos_t filepos;
+ lws_filepos_t filelen;
+ lws_fop_fd_t fop_fd;
#if defined(LWS_WITH_RANGES)
struct lws_range_parsing range;
lws_union_transition(wsi, LWSCM_HTTP_SERVING_ACCEPTED);
wsi->state = LWSS_HTTP;
- wsi->u.http.fd = LWS_INVALID_FILE;
+ wsi->u.http.fop_fd = NULL;
/* expose it at the same offset as u.hdr */
wsi->u.http.ah = ah;
unsigned char *p = response;
unsigned char *end = p + context->pt_serv_buf_size - LWS_PRE;
unsigned long computed_total_content_length;
- int ret = 0, cclen = 8, n = HTTP_STATUS_OK, fflags = O_RDONLY;
+ int ret = 0, cclen = 8, n = HTTP_STATUS_OK;
+ lws_fop_flags_t fflags = O_RDONLY;
#if defined(LWS_WITH_RANGES)
int ranges;
#endif
}
- wsi->u.http.fd = lws_plat_file_open(wsi, file, &wsi->u.http.filelen,
- &fflags);
- if (wsi->u.http.fd == LWS_INVALID_FILE) {
+ wsi->u.http.fop_fd = lws_plat_file_open(&wsi->context->fops, file,
+ &wsi->u.http.filelen,
+ &fflags);
+ if (!wsi->u.http.fop_fd) {
lwsl_err("Unable to open '%s'\n", file);
return -1;
/* check for the "send a big file by hand" example case */
if (!strcmp((const char *)in, "/leaf.jpg")) {
+ lws_fop_flags_t flags = LWS_O_RDONLY;
+
if (strlen(resource_path) > sizeof(leaf_path) - 10)
return -1;
sprintf(leaf_path, "%s/leaf.jpg", resource_path);
p = buffer + LWS_PRE;
end = p + sizeof(buffer) - LWS_PRE;
- pss->fd = lws_plat_file_open(wsi, leaf_path, &file_len,
- LWS_O_RDONLY);
+ pss->fop_fd = lws_plat_file_open(lws_get_fops(lws_get_context(wsi)),
+ leaf_path, &file_len, &flags);
- if (pss->fd == LWS_INVALID_FILE) {
+ if (!pss->fop_fd) {
lwsl_err("failed to open file %s\n", leaf_path);
return -1;
}
p - (buffer + LWS_PRE),
LWS_WRITE_HTTP_HEADERS);
if (n < 0) {
- lws_plat_file_close(wsi, pss->fd);
+ lws_plat_file_close(pss->fop_fd);
return -1;
}
/*
if (pss->client_finished)
return -1;
- if (pss->fd == LWS_INVALID_FILE)
+ if (!pss->fop_fd)
goto try_to_reuse;
#ifndef LWS_NO_CLIENT
/* he couldn't handle that much */
n = m;
- n = lws_plat_file_read(wsi, pss->fd,
+ n = lws_plat_file_read(pss->fop_fd,
&amount, buffer + LWS_PRE, n);
/* problem reading, close conn */
if (n < 0) {
lws_callback_on_writable(wsi);
break;
penultimate:
- lws_plat_file_close(wsi, pss->fd);
- pss->fd = LWS_INVALID_FILE;
+ lws_plat_file_close(pss->fop_fd);
+ pss->fop_fd = NULL;
goto try_to_reuse;
bail:
- lws_plat_file_close(wsi, pss->fd);
+ lws_plat_file_close(pss->fop_fd);
return -1;
* to do any of this unless you have a reason (eg, want to serve
* compressed files without decompressing the whole archive)
*/
-static lws_filefd_type
-test_server_fops_open(struct lws *wsi, const char *filename,
- unsigned long *filelen, int *flags)
+static lws_fop_fd_t
+test_server_fops_open(struct lws_plat_file_ops *fops, const char *filename,
+ lws_filepos_t *filelen, lws_fop_flags_t *flags)
{
- lws_filefd_type n;
+ lws_fop_fd_t n;
/* call through to original platform implementation */
- n = fops_plat.open(wsi, filename, filelen, flags);
+ n = fops_plat.open(fops, filename, filelen, flags);
- lwsl_notice("%s: opening %s, ret %ld, len %lu\n", __func__, filename,
- (long)n, *filelen);
+ lwsl_notice("%s: opening %s, ret %p, len %lu\n", __func__, filename,
+ n, *filelen);
return n;
}
* to do any of this unless you have a reason (eg, want to serve
* compressed files without decompressing the whole archive)
*/
-static lws_filefd_type
-test_server_fops_open(struct lws *wsi, const char *filename,
- unsigned long *filelen, int *flags)
+static lws_fop_fd_t
+test_server_fops_open(struct lws_plat_file_ops *fops,
+ const char *filename,
+ lws_filepos_t *filelen,
+ lws_fop_flags_t *flags)
{
- lws_filefd_type n;
+ lws_fop_fd_t fop_fd;
/* call through to original platform implementation */
- n = fops_plat.open(wsi, filename, filelen, flags);
+ fop_fd = fops_plat.open(fops, filename, filelen, flags);
- lwsl_info("%s: opening %s, ret %ld, len %lu\n", __func__, filename,
- (long)n, *filelen);
+ lwsl_info("%s: opening %s, ret %p, len %lu\n", __func__, filename,
+ fop_fd, (long)*filelen);
- return n;
+ return fop_fd;
}
void sighandler(int sig)
#endif
struct per_session_data__http {
- lws_filefd_type fd;
+ lws_fop_fd_t fop_fd;
#ifdef LWS_WITH_CGI
struct lws_cgi_args args;
#endif