mirror of
https://github.com/nginx/nginx.git
synced 2024-11-27 03:10:17 -06:00
nginx-0.0.1-2003-11-13-19:16:33 import
This commit is contained in:
parent
562e53ea7d
commit
45890ea8c1
@ -30,7 +30,7 @@ typedef struct ngx_connection_s ngx_connection_t;
|
|||||||
#include <ngx_times.h>
|
#include <ngx_times.h>
|
||||||
#include <ngx_inet.h>
|
#include <ngx_inet.h>
|
||||||
#include <ngx_conf_file.h>
|
#include <ngx_conf_file.h>
|
||||||
#include <ngx_os_init.h>
|
#include <ngx_os.h>
|
||||||
#include <ngx_connection.h>
|
#include <ngx_connection.h>
|
||||||
|
|
||||||
|
|
||||||
|
@ -87,30 +87,52 @@ ngx_log_debug(r->connection->log, "HTTP filename: '%s'" _ r->file.name.data);
|
|||||||
|
|
||||||
#if (WIN9X)
|
#if (WIN9X)
|
||||||
|
|
||||||
/*
|
if (ngx_win32_version < NGX_WIN_NT) {
|
||||||
* There is no way to open a file or a directory in Win9X with
|
|
||||||
* one syscall: Win9X has no FILE_FLAG_BACKUP_SEMANTICS flag.
|
|
||||||
* So we need to check its type before the opening
|
|
||||||
*/
|
|
||||||
|
|
||||||
r->file.info.dwFileAttributes = GetFileAttributes(r->file.name.data);
|
/*
|
||||||
if (r->file.info.dwFileAttributes == INVALID_FILE_ATTRIBUTES) {
|
* There is no way to open a file or a directory in Win9X with
|
||||||
err = ngx_errno;
|
* one syscall: Win9X has no FILE_FLAG_BACKUP_SEMANTICS flag.
|
||||||
ngx_log_error(NGX_LOG_ERR, r->connection->log, err,
|
* So we need to check its type before the opening.
|
||||||
ngx_file_type_n " \"%s\" failed", r->file.name.data);
|
*/
|
||||||
|
|
||||||
if (err == NGX_ENOENT || err == NGX_ENOTDIR) {
|
r->file.info.dwFileAttributes = GetFileAttributes(r->file.name.data);
|
||||||
return NGX_HTTP_NOT_FOUND;
|
if (r->file.info.dwFileAttributes == INVALID_FILE_ATTRIBUTES) {
|
||||||
|
err = ngx_errno;
|
||||||
|
ngx_log_error(NGX_LOG_ERR, r->connection->log, err,
|
||||||
|
ngx_file_type_n " \"%s\" failed", r->file.name.data);
|
||||||
|
|
||||||
} else if (err == NGX_EACCES) {
|
if (err == NGX_ENOENT || err == NGX_ENOTDIR) {
|
||||||
return NGX_HTTP_FORBIDDEN;
|
return NGX_HTTP_NOT_FOUND;
|
||||||
|
|
||||||
} else {
|
} else if (err == NGX_EACCES) {
|
||||||
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
return NGX_HTTP_FORBIDDEN;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ngx_is_dir(r->file.info)) {
|
||||||
|
ngx_log_debug(r->connection->log, "HTTP DIR: '%s'" _ r->file.name.data);
|
||||||
|
|
||||||
|
if (!(r->headers_out.location =
|
||||||
|
ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
|
||||||
|
{
|
||||||
|
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
*last++ = '/';
|
||||||
|
*last = '\0';
|
||||||
|
r->headers_out.location->key.len = 8;
|
||||||
|
r->headers_out.location->key.data = "Location" ;
|
||||||
|
r->headers_out.location->value.len = last - location;
|
||||||
|
r->headers_out.location->value.data = location;
|
||||||
|
|
||||||
|
return NGX_HTTP_MOVED_PERMANENTLY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#endif
|
||||||
|
|
||||||
if (r->file.fd == NGX_INVALID_FILE) {
|
if (r->file.fd == NGX_INVALID_FILE) {
|
||||||
r->file.fd = ngx_open_file(r->file.name.data,
|
r->file.fd = ngx_open_file(r->file.name.data,
|
||||||
@ -163,7 +185,6 @@ ngx_log_debug(r->connection->log, "FILE: %d" _ r->file.fd);
|
|||||||
if (ngx_is_dir(r->file.info)) {
|
if (ngx_is_dir(r->file.info)) {
|
||||||
ngx_log_debug(r->connection->log, "HTTP DIR: '%s'" _ r->file.name.data);
|
ngx_log_debug(r->connection->log, "HTTP DIR: '%s'" _ r->file.name.data);
|
||||||
|
|
||||||
#if !(WIN9X)
|
|
||||||
if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) {
|
if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) {
|
||||||
ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno,
|
ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno,
|
||||||
ngx_close_file_n " \"%s\" failed", r->file.name.data);
|
ngx_close_file_n " \"%s\" failed", r->file.name.data);
|
||||||
@ -171,7 +192,6 @@ ngx_log_debug(r->connection->log, "HTTP DIR: '%s'" _ r->file.name.data);
|
|||||||
|
|
||||||
r->file.fd = NGX_INVALID_FILE;
|
r->file.fd = NGX_INVALID_FILE;
|
||||||
r->file.info_valid = 0;
|
r->file.info_valid = 0;
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!(r->headers_out.location =
|
if (!(r->headers_out.location =
|
||||||
ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
|
ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
|
||||||
@ -202,7 +222,6 @@ ngx_log_debug(r->connection->log, "HTTP DIR: '%s'" _ r->file.name.data);
|
|||||||
return NGX_HTTP_NOT_FOUND;
|
return NGX_HTTP_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
r->content_handler = ngx_http_static_handler;
|
r->content_handler = ngx_http_static_handler;
|
||||||
|
@ -4,9 +4,6 @@
|
|||||||
#include <ngx_event.h>
|
#include <ngx_event.h>
|
||||||
#include <ngx_http.h>
|
#include <ngx_http.h>
|
||||||
#include <nginx.h>
|
#include <nginx.h>
|
||||||
#if __FreeBSD__
|
|
||||||
#include <ngx_freebsd_init.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
static void ngx_http_phase_event_handler(ngx_event_t *rev);
|
static void ngx_http_phase_event_handler(ngx_event_t *rev);
|
||||||
|
16
src/os/unix/ngx_freebsd.h
Normal file
16
src/os/unix/ngx_freebsd.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#ifndef _NGX_FREEBSD_H_INCLUDED_
|
||||||
|
#define _NGX_FREEBSD_H_INCLUDED_
|
||||||
|
|
||||||
|
|
||||||
|
ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in);
|
||||||
|
|
||||||
|
|
||||||
|
extern int ngx_freebsd_kern_osreldate;
|
||||||
|
extern int ngx_freebsd_hw_ncpu;
|
||||||
|
extern int ngx_freebsd_net_inet_tcp_sendspace;
|
||||||
|
extern int ngx_freebsd_sendfile_nbytes_bug;
|
||||||
|
extern int ngx_freebsd_kern_ipc_zero_copy_send;
|
||||||
|
extern int ngx_freebsd_use_tcp_nopush;
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* _NGX_FREEBSD_H_INCLUDED_ */
|
@ -24,23 +24,35 @@
|
|||||||
#include <osreldate.h>
|
#include <osreldate.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* TODO: autoconf */
|
||||||
|
#if __FreeBSD_version < 300007
|
||||||
|
typedef u_int64_t uint64_t;
|
||||||
|
typedef u_int32_t uintptr_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if __FreeBSD_version < 330002 /* exactly */
|
||||||
|
typedef uint32_t socklen_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if (i386)
|
#if (i386)
|
||||||
|
|
||||||
#define OFF_FMT "%lld"
|
#define OFF_FMT "%lld"
|
||||||
#define SIZE_FMT "%d"
|
#define SIZE_FMT "%d"
|
||||||
#define SIZEX_FMT "%x"
|
#define SIZEX_FMT "%x"
|
||||||
#define TIME_FMT "%lu"
|
|
||||||
|
|
||||||
#else /* amd64, alpha, sparc64, ia64 */
|
#else /* amd64, alpha, sparc64, ia64 */
|
||||||
|
|
||||||
#define OFF_FMT "%ld"
|
#define OFF_FMT "%ld"
|
||||||
#define SIZE_FMT "%ld"
|
#define SIZE_FMT "%ld"
|
||||||
#define SIZEX_FMT "%lx"
|
#define SIZEX_FMT "%lx"
|
||||||
#define TIME_FMT "%lu"
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define TIME_FMT "%lu"
|
||||||
#define PID_FMT "%d"
|
#define PID_FMT "%d"
|
||||||
|
#define RLIM_FMT "%lld"
|
||||||
|
|
||||||
|
|
||||||
#ifndef HAVE_SELECT
|
#ifndef HAVE_SELECT
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
#include <ngx_freebsd_init.h>
|
#include <ngx_config.h>
|
||||||
|
#include <ngx_core.h>
|
||||||
|
|
||||||
|
|
||||||
/* FreeBSD 3.4 at least */
|
/* FreeBSD 3.4 at least */
|
||||||
|
@ -1,26 +0,0 @@
|
|||||||
#ifndef _NGX_FREEBSD_INIT_H_INCLUDED_
|
|
||||||
#define _NGX_FREEBSD_INIT_H_INCLUDED_
|
|
||||||
|
|
||||||
|
|
||||||
#include <ngx_config.h>
|
|
||||||
#include <ngx_core.h>
|
|
||||||
|
|
||||||
|
|
||||||
/* STUB */
|
|
||||||
int ngx_posix_init(ngx_log_t *log);
|
|
||||||
ssize_t ngx_unix_recv(ngx_connection_t *c, char *buf, size_t size);
|
|
||||||
ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *entry);
|
|
||||||
/* */
|
|
||||||
|
|
||||||
ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in);
|
|
||||||
|
|
||||||
|
|
||||||
extern int ngx_freebsd_kern_osreldate;
|
|
||||||
extern int ngx_freebsd_hw_ncpu;
|
|
||||||
extern int ngx_freebsd_net_inet_tcp_sendspace;
|
|
||||||
extern int ngx_freebsd_sendfile_nbytes_bug;
|
|
||||||
extern int ngx_freebsd_kern_ipc_zero_copy_send;
|
|
||||||
extern int ngx_freebsd_use_tcp_nopush;
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* _NGX_FREEBSD_INIT_H_INCLUDED_ */
|
|
@ -2,7 +2,6 @@
|
|||||||
#include <ngx_config.h>
|
#include <ngx_config.h>
|
||||||
#include <ngx_core.h>
|
#include <ngx_core.h>
|
||||||
#include <ngx_event.h>
|
#include <ngx_event.h>
|
||||||
#include <ngx_freebsd_init.h>
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -34,8 +34,9 @@
|
|||||||
#define OFF_FMT "%lld"
|
#define OFF_FMT "%lld"
|
||||||
#define SIZE_FMT "%d"
|
#define SIZE_FMT "%d"
|
||||||
#define SIZEX_FMT "%x"
|
#define SIZEX_FMT "%x"
|
||||||
#define PID_FMT "%d"
|
|
||||||
#define TIME_FMT "%lu"
|
#define TIME_FMT "%lu"
|
||||||
|
#define PID_FMT "%d"
|
||||||
|
#define RLIM_FMT "%lu"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,12 +3,6 @@
|
|||||||
#include <ngx_core.h>
|
#include <ngx_core.h>
|
||||||
|
|
||||||
|
|
||||||
/* STUB */
|
|
||||||
ssize_t ngx_unix_recv(ngx_connection_t *c, char *buf, size_t size);
|
|
||||||
ngx_chain_t *ngx_writev_chain(ngx_connection_t *c, ngx_chain_t *in);
|
|
||||||
int ngx_posix_init(ngx_log_t *log);
|
|
||||||
|
|
||||||
|
|
||||||
char ngx_linux_kern_ostype[50];
|
char ngx_linux_kern_ostype[50];
|
||||||
char ngx_linux_kern_osrelease[20];
|
char ngx_linux_kern_osrelease[20];
|
||||||
|
|
||||||
|
58
src/os/unix/ngx_os.h
Normal file
58
src/os/unix/ngx_os.h
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
#ifndef _NGX_OS_H_INCLUDED_
|
||||||
|
#define _NGX_OS_H_INCLUDED_
|
||||||
|
|
||||||
|
|
||||||
|
#include <ngx_config.h>
|
||||||
|
#include <ngx_core.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define NGX_IO_SENDFILE 1
|
||||||
|
#define NGX_IO_ZEROCOPY 2
|
||||||
|
|
||||||
|
#if (HAVE_SENDFILE)
|
||||||
|
#define NGX_HAVE_SENDFILE NGX_IO_SENDFILE
|
||||||
|
#else
|
||||||
|
#define NGX_HAVE_SENDFILE 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (HAVE_ZEROCOPY)
|
||||||
|
#define NGX_HAVE_ZEROCOPY NGX_IO_ZEROCOPY
|
||||||
|
#else
|
||||||
|
#define NGX_HAVE_ZEROCOPY 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
ssize_t (*recv)(ngx_connection_t *c, char *buf, size_t size);
|
||||||
|
ssize_t (*recv_chain)(ngx_connection_t *c, ngx_chain_t *in);
|
||||||
|
ssize_t (*send)(ngx_connection_t *c, char *buf, size_t size);
|
||||||
|
ngx_chain_t *(*send_chain)(ngx_connection_t *c, ngx_chain_t *in);
|
||||||
|
int flags;
|
||||||
|
} ngx_os_io_t;
|
||||||
|
|
||||||
|
|
||||||
|
int ngx_os_init(ngx_log_t *log);
|
||||||
|
int ngx_daemon(ngx_log_t *log);
|
||||||
|
int ngx_posix_init(ngx_log_t *log);
|
||||||
|
|
||||||
|
ssize_t ngx_unix_recv(ngx_connection_t *c, char *buf, size_t size);
|
||||||
|
ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *entry);
|
||||||
|
ngx_chain_t *ngx_writev_chain(ngx_connection_t *c, ngx_chain_t *in);
|
||||||
|
|
||||||
|
|
||||||
|
extern ngx_os_io_t ngx_os_io;
|
||||||
|
extern int ngx_max_sockets;
|
||||||
|
extern int ngx_inherited_nonblocking;
|
||||||
|
|
||||||
|
|
||||||
|
extern int restart;
|
||||||
|
extern int rotate;
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __FreeBSD__
|
||||||
|
#include <ngx_freebsd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* _NGX_OS_H_INCLUDED_ */
|
@ -47,7 +47,7 @@ int ngx_posix_init(ngx_log_t *log)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngx_log_error(NGX_LOG_INFO, log, 0,
|
ngx_log_error(NGX_LOG_INFO, log, 0,
|
||||||
"getrlimit(RLIMIT_NOFILE): %qd:%qd",
|
"getrlimit(RLIMIT_NOFILE): " RLIM_FMT ":" RLIM_FMT,
|
||||||
rlmt.rlim_cur, rlmt.rlim_max);
|
rlmt.rlim_cur, rlmt.rlim_max);
|
||||||
|
|
||||||
ngx_max_sockets = rlmt.rlim_cur;
|
ngx_max_sockets = rlmt.rlim_cur;
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include <sys/filio.h> /* FIONBIO */
|
#include <sys/filio.h> /* FIONBIO */
|
||||||
#include <sys/stropts.h> /* INFTIM */
|
#include <sys/stropts.h> /* INFTIM */
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#include <sys/systeminfo.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
@ -32,8 +33,9 @@ typedef uint32_t u_int32_t;
|
|||||||
#define OFF_FMT "%lld"
|
#define OFF_FMT "%lld"
|
||||||
#define SIZE_FMT "%d"
|
#define SIZE_FMT "%d"
|
||||||
#define SIZEX_FMT "%x"
|
#define SIZEX_FMT "%x"
|
||||||
#define PID_FMT "%ld"
|
|
||||||
#define TIME_FMT "%lu"
|
#define TIME_FMT "%lu"
|
||||||
|
#define PID_FMT "%ld"
|
||||||
|
#define RLIM_FMT "%lu"
|
||||||
|
|
||||||
|
|
||||||
#ifndef HAVE_SELECT
|
#ifndef HAVE_SELECT
|
||||||
|
51
src/os/unix/ngx_solaris_init.c
Normal file
51
src/os/unix/ngx_solaris_init.c
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
|
||||||
|
#include <ngx_config.h>
|
||||||
|
#include <ngx_core.h>
|
||||||
|
|
||||||
|
|
||||||
|
char ngx_solaris_sysname[20];
|
||||||
|
char ngx_solaris_release[10];
|
||||||
|
char ngx_solaris_version[50];
|
||||||
|
|
||||||
|
|
||||||
|
ngx_os_io_t ngx_os_io = {
|
||||||
|
ngx_unix_recv,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
ngx_writev_chain,
|
||||||
|
NGX_HAVE_ZEROCOPY
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
int ngx_os_init(ngx_log_t *log)
|
||||||
|
{
|
||||||
|
if (sysinfo(SI_SYSNAME, ngx_solaris_sysname, sizeof(ngx_solaris_sysname))
|
||||||
|
== -1)
|
||||||
|
{
|
||||||
|
ngx_log_error(NGX_LOG_ALERT, log, errno, "sysinfo(SI_SYSNAME) failed");
|
||||||
|
return NGX_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sysinfo(SI_RELEASE, ngx_solaris_release, sizeof(ngx_solaris_release))
|
||||||
|
== -1)
|
||||||
|
{
|
||||||
|
ngx_log_error(NGX_LOG_ALERT, log, errno, "sysinfo(SI_RELEASE) failed");
|
||||||
|
return NGX_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sysinfo(SI_VERSION, ngx_solaris_version, sizeof(ngx_solaris_version))
|
||||||
|
== -1)
|
||||||
|
{
|
||||||
|
ngx_log_error(NGX_LOG_ALERT, log, errno, "sysinfo(SI_SYSNAME) failed");
|
||||||
|
return NGX_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
ngx_log_error(NGX_LOG_INFO, log, 0, "OS: %s %s"
|
||||||
|
ngx_solaris_sysname, ngx_solaris_release);
|
||||||
|
|
||||||
|
ngx_log_error(NGX_LOG_INFO, log, 0, "version: %s",
|
||||||
|
ngx_solaris_version);
|
||||||
|
|
||||||
|
|
||||||
|
return ngx_posix_init(log);
|
||||||
|
}
|
@ -20,7 +20,10 @@ typedef struct tm ngx_tm_t;
|
|||||||
#define ngx_tm_mon tm_mon
|
#define ngx_tm_mon tm_mon
|
||||||
#define ngx_tm_year tm_year
|
#define ngx_tm_year tm_year
|
||||||
#define ngx_tm_wday tm_wday
|
#define ngx_tm_wday tm_wday
|
||||||
|
|
||||||
|
#ifndef SOLARIS
|
||||||
#define ngx_tm_zone tm_zone
|
#define ngx_tm_zone tm_zone
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void ngx_localtime(ngx_tm_t *tm);
|
void ngx_localtime(ngx_tm_t *tm);
|
||||||
|
@ -6,26 +6,49 @@
|
|||||||
ssize_t ngx_read_file(ngx_file_t *file, char *buf, size_t size, off_t offset)
|
ssize_t ngx_read_file(ngx_file_t *file, char *buf, size_t size, off_t offset)
|
||||||
{
|
{
|
||||||
size_t n;
|
size_t n;
|
||||||
long high_offset;
|
|
||||||
ngx_err_t err;
|
|
||||||
OVERLAPPED ovlp, *povlp;
|
OVERLAPPED ovlp, *povlp;
|
||||||
|
|
||||||
|
#if (WIN9X)
|
||||||
|
|
||||||
if (ngx_win32_version < NGX_WIN_NT) {
|
if (ngx_win32_version < NGX_WIN_NT) {
|
||||||
high_offset = (long) (offset >> 32);
|
long high_offset;
|
||||||
if (SetFilePointer(file->fd, (long) offset, &high_offset, FILE_BEGIN)
|
ngx_err_t err;
|
||||||
== 0xFFFFFFFF)
|
|
||||||
{
|
/*
|
||||||
err = ngx_errno;
|
* in Win9X the overlapped pointer must be NULL
|
||||||
if (err != NO_ERROR) {
|
* so we need to use SetFilePointer() to set the offset
|
||||||
ngx_log_error(NGX_LOG_ERR, file->log, err,
|
*/
|
||||||
"SeekFilePointer() failed");
|
|
||||||
return NGX_ERROR;
|
if (file->offset != offset) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* the maximum file size on FAT16 is 2G, but on FAT32 it's 4G so we
|
||||||
|
* need to use high_offset because a single offset is signed value
|
||||||
|
*/
|
||||||
|
|
||||||
|
high_offset = (long) (offset >> 32);
|
||||||
|
if (SetFilePointer(file->fd, (long) offset, &high_offset,
|
||||||
|
FILE_BEGIN) == INVALID_SET_FILE_POINTER)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* INVALID_SET_FILE_POINTER is 0xffffffff and it can be valid
|
||||||
|
* value for large file so we need also to check GetLastError()
|
||||||
|
*/
|
||||||
|
|
||||||
|
err = ngx_errno;
|
||||||
|
if (err != NO_ERROR) {
|
||||||
|
ngx_log_error(NGX_LOG_ERR, file->log, err,
|
||||||
|
"SeekFilePointer() failed");
|
||||||
|
return NGX_ERROR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
povlp = NULL;
|
povlp = NULL;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
#endif
|
||||||
ovlp.Internal = 0;
|
ovlp.Internal = 0;
|
||||||
ovlp.InternalHigh = 0;
|
ovlp.InternalHigh = 0;
|
||||||
ovlp.Offset = (DWORD) offset;
|
ovlp.Offset = (DWORD) offset;
|
||||||
@ -33,7 +56,10 @@ ssize_t ngx_read_file(ngx_file_t *file, char *buf, size_t size, off_t offset)
|
|||||||
ovlp.hEvent = NULL;
|
ovlp.hEvent = NULL;
|
||||||
|
|
||||||
povlp = &ovlp;
|
povlp = &ovlp;
|
||||||
|
|
||||||
|
#if (WIN9X)
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (ReadFile(file->fd, buf, size, &n, povlp) == 0) {
|
if (ReadFile(file->fd, buf, size, &n, povlp) == 0) {
|
||||||
ngx_log_error(NGX_LOG_ERR, file->log, ngx_errno, "ReadFile() failed");
|
ngx_log_error(NGX_LOG_ERR, file->log, ngx_errno, "ReadFile() failed");
|
||||||
@ -46,13 +72,66 @@ ssize_t ngx_read_file(ngx_file_t *file, char *buf, size_t size, off_t offset)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* TODO: as read file */
|
|
||||||
|
|
||||||
ssize_t ngx_write_file(ngx_file_t *file, char *buf, size_t size, off_t offset)
|
ssize_t ngx_write_file(ngx_file_t *file, char *buf, size_t size, off_t offset)
|
||||||
{
|
{
|
||||||
size_t n;
|
size_t n;
|
||||||
|
OVERLAPPED ovlp, *povlp;
|
||||||
|
|
||||||
if (WriteFile(file->fd, buf, size, &n, NULL) == 0) {
|
#if (WIN9X)
|
||||||
|
|
||||||
|
if (ngx_win32_version < NGX_WIN_NT) {
|
||||||
|
long high_offset;
|
||||||
|
ngx_err_t err;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* in Win9X the overlapped pointer must be NULL
|
||||||
|
* so we need to use SetFilePointer() to set the offset
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (file->offset != offset) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* the maximum file size on FAT16 is 2G, but on FAT32 it's 4G so we
|
||||||
|
* need to use high_offset because a single offset is signed value
|
||||||
|
*/
|
||||||
|
|
||||||
|
high_offset = (long) (offset >> 32);
|
||||||
|
if (SetFilePointer(file->fd, (long) offset, &high_offset,
|
||||||
|
FILE_BEGIN) == INVALID_SET_FILE_POINTER)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* INVALID_SET_FILE_POINTER is 0xffffffff and it can be valid
|
||||||
|
* value for large file so we need also to check GetLastError()
|
||||||
|
*/
|
||||||
|
|
||||||
|
err = ngx_errno;
|
||||||
|
if (err != NO_ERROR) {
|
||||||
|
ngx_log_error(NGX_LOG_ERR, file->log, err,
|
||||||
|
"SeekFilePointer() failed");
|
||||||
|
return NGX_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
povlp = NULL;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ovlp.Internal = 0;
|
||||||
|
ovlp.InternalHigh = 0;
|
||||||
|
ovlp.Offset = (DWORD) offset;
|
||||||
|
ovlp.OffsetHigh = (DWORD) (offset >> 32);
|
||||||
|
ovlp.hEvent = NULL;
|
||||||
|
|
||||||
|
povlp = &ovlp;
|
||||||
|
|
||||||
|
#if (WIN9X)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (WriteFile(file->fd, buf, size, &n, povlp) == 0) {
|
||||||
ngx_log_error(NGX_LOG_ERR, file->log, ngx_errno, "WriteFile() failed");
|
ngx_log_error(NGX_LOG_ERR, file->log, ngx_errno, "WriteFile() failed");
|
||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
@ -63,12 +142,15 @@ ssize_t ngx_write_file(ngx_file_t *file, char *buf, size_t size, off_t offset)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* TODO: log error */
|
|
||||||
|
|
||||||
int ngx_file_append_mode(ngx_fd_t fd)
|
int ngx_file_append_mode(ngx_fd_t fd)
|
||||||
{
|
{
|
||||||
if (SetFilePointer(fd, 0, NULL, FILE_END) == 0xFFFFFFFF) {
|
ngx_err_t err;
|
||||||
if (GetLastError() != NO_ERROR) {
|
|
||||||
|
if (SetFilePointer(fd, 0, NULL, FILE_END) == INVALID_SET_FILE_POINTER) {
|
||||||
|
err = ngx_errno;
|
||||||
|
if (err != NO_ERROR) {
|
||||||
|
ngx_log_error(NGX_LOG_ERR, file->log, err,
|
||||||
|
"SeekFilePointer() failed");
|
||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,17 @@
|
|||||||
#include <ngx_core.h>
|
#include <ngx_core.h>
|
||||||
|
|
||||||
|
|
||||||
/* INVALID_FILE_ATTRIBUTES specified but not defined at least in MSVC6SP2 */
|
/* INVALID_FILE_ATTRIBUTES is specified but not defined at least in MSVC6SP2 */
|
||||||
#ifndef INVALID_FILE_ATTRIBUTES
|
#ifndef INVALID_FILE_ATTRIBUTES
|
||||||
#define INVALID_FILE_ATTRIBUTES 0xFFFFFFFF
|
#define INVALID_FILE_ATTRIBUTES 0xffffffff
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* INVALID_SET_FILE_POINTER is not defined at least in MSVC6SP2 */
|
||||||
|
#ifndef INVALID_SET_FILE_POINTER
|
||||||
|
#define INVALID_SET_FILE_POINTER 0xffffffff
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define NGX_INVALID_FILE INVALID_HANDLE_VALUE
|
#define NGX_INVALID_FILE INVALID_HANDLE_VALUE
|
||||||
#define NGX_FILE_ERROR 0
|
#define NGX_FILE_ERROR 0
|
||||||
|
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
#ifndef _NGX_OS_INIT_H_INCLUDED_
|
ifndef _NGX_OS_H_INCLUDED_
|
||||||
#define _NGX_OS_INIT_H_INCLUDED_
|
#define _NGX_OS_H_INCLUDED_
|
||||||
|
|
||||||
|
|
||||||
#include <ngx_config.h>
|
#include <ngx_config.h>
|
||||||
#include <ngx_core.h>
|
#include <ngx_core.h>
|
||||||
|
|
||||||
|
|
||||||
#define NGX_IO_SENDFILE 1
|
#define NGX_IO_SENDFILE 1
|
||||||
#define NGX_IO_ZEROCOPY 2
|
#define NGX_IO_ZEROCOPY 2
|
||||||
|
|
||||||
@ -34,18 +33,17 @@ typedef struct {
|
|||||||
|
|
||||||
int ngx_os_init(ngx_log_t *log);
|
int ngx_os_init(ngx_log_t *log);
|
||||||
|
|
||||||
#if !(WIN32)
|
|
||||||
int ngx_daemon(ngx_log_t *log);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
extern ngx_os_io_t ngx_os_io;
|
extern ngx_os_io_t ngx_os_io;
|
||||||
extern int ngx_max_sockets;
|
extern int ngx_max_sockets;
|
||||||
extern int ngx_inherited_nonblocking;
|
extern int ngx_inherited_nonblocking;
|
||||||
|
extern int ngx_win32_version;
|
||||||
|
|
||||||
|
|
||||||
extern int restart;
|
extern int restart;
|
||||||
extern int rotate;
|
extern int rotate;
|
||||||
|
|
||||||
|
|
||||||
#endif /* _NGX_OS_INIT_H_INCLUDED_ */
|
|
||||||
|
#endif /* _NGX_OS_H_INCLUDED_ */
|
||||||
|
|
@ -4,10 +4,7 @@
|
|||||||
|
|
||||||
#define WIN32 1
|
#define WIN32 1
|
||||||
|
|
||||||
/* STUB */
|
|
||||||
#define NGX_WIN_NT 200000
|
#define NGX_WIN_NT 200000
|
||||||
extern int ngx_win32_version;
|
|
||||||
/**/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user