fixed sendfile() for freebsd

This commit is contained in:
hyung-hwan 2014-11-08 16:10:35 +00:00
parent 3ab19cb3b8
commit ca04358d50
4 changed files with 60 additions and 50 deletions

View File

@ -29,30 +29,10 @@
#include "awk.h" #include "awk.h"
#include "std.h" #include "std.h"
#if defined(_WIN32) #include <stdlib.h>
# include <windows.h>
# include <tchar.h>
# if defined(QSE_HAVE_CONFIG_H)
# include <ltdl.h>
# define USE_LTDL
# endif
#elif defined(__OS2__)
# define INCL_DOSMODULEMGR
# define INCL_DOSPROCESS
# define INCL_DOSERRORS
# include <os2.h>
#elif defined(__DOS__)
# if !defined(QSE_ENABLE_STATIC_MODULE)
# include <cwdllfnc.h>
# endif
#else
# include <unistd.h>
# include <ltdl.h>
# define USE_LTDL
#endif
#ifndef QSE_HAVE_CONFIG_H #if !defined(QSE_HAVE_CONFIG_H)
# if defined(_WIN32) || defined(__OS2__) || defined(__DOS__) # if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
# define HAVE_POW # define HAVE_POW
# define HAVE_FMOD # define HAVE_FMOD
# endif # endif
@ -128,13 +108,7 @@ int StdAwk::open ()
goto oops; goto oops;
} }
#if defined(USE_LTDL) if (qse_awk_stdmodstartup (this->awk) <= -1) goto oops;
/* lt_dlinit() can be called more than once and
* lt_dlexit() shuts down libltdl if it's called as many times as
* corresponding lt_dlinit(). so it's safe to call lt_dlinit()
* and lt_dlexit() at the library level. */
if (lt_dlinit() != 0) goto oops;
#endif
this->cmgrtab_inited = false; this->cmgrtab_inited = false;
return 0; return 0;
@ -153,11 +127,8 @@ void StdAwk::close ()
} }
clearConsoleOutputs (); clearConsoleOutputs ();
qse_awk_stdmodshutdown (this->awk);
Awk::close (); Awk::close ();
#if defined(USE_LTDL)
lt_dlexit ();
#endif
} }
StdAwk::Run* StdAwk::parse (Source& in, Source& out) StdAwk::Run* StdAwk::parse (Source& in, Source& out)

View File

@ -175,6 +175,38 @@ qse_awk_flt_t qse_awk_stdmathmod (qse_awk_t* awk, qse_awk_flt_t x, qse_awk_flt_t
#endif #endif
} }
int qse_awk_stdmodstartup (qse_awk_t* awk)
{
#if defined(QSE_ENABLE_STATIC_MODULE)
return 0;
#elif defined(USE_LTDL)
/* lt_dlinit() can be called more than once and
* lt_dlexit() shuts down libltdl if it's called as many times as
* corresponding lt_dlinit(). so it's safe to call lt_dlinit()
* and lt_dlexit() at the library level. */
return (lt_dlinit () != 0)? -1: 0;
#else
return 0;
#endif
}
void qse_awk_stdmodshutdown (qse_awk_t* awk)
{
#if defined(QSE_ENABLE_STATIC_MODULE)
/* do nothign */
#elif defined(USE_LTDL)
lt_dlexit ();
#else
/* do nothing */
#endif
}
void* qse_awk_stdmodopen (qse_awk_t* awk, const qse_awk_mod_spec_t* spec) void* qse_awk_stdmodopen (qse_awk_t* awk, const qse_awk_mod_spec_t* spec)
{ {
#if defined(QSE_ENABLE_STATIC_MODULE) #if defined(QSE_ENABLE_STATIC_MODULE)
@ -389,10 +421,7 @@ qse_awk_t* qse_awk_openstd (qse_size_t xtnsize, qse_awk_errnum_t* errnum)
static void fini_xtn (qse_awk_t* awk) static void fini_xtn (qse_awk_t* awk)
{ {
/* nothing to do */ qse_awk_stdmodshutdown (awk);
#if defined(USE_LTDL)
lt_dlexit ();
#endif
} }
static void clear_xtn (qse_awk_t* awk) static void clear_xtn (qse_awk_t* awk)
@ -424,13 +453,7 @@ qse_awk_t* qse_awk_openstdwithmmgr (qse_mmgr_t* mmgr, qse_size_t xtnsize, qse_aw
if (add_globals(awk) <= -1 || if (add_globals(awk) <= -1 ||
add_functions (awk) <= -1) goto oops; add_functions (awk) <= -1) goto oops;
#if defined(USE_LTDL) if (qse_awk_stdmodstartup (awk) <= -1) goto oops;
/* lt_dlinit() can be called more than once and
* lt_dlexit() shuts down libltdl if it's called as many times as
* corresponding lt_dlinit(). so it's safe to call lt_dlinit()
* and lt_dlexit() at the library level. */
if (lt_dlinit () != 0) goto oops;
#endif
xtn->ecb.close = fini_xtn; xtn->ecb.close = fini_xtn;
xtn->ecb.clear = clear_xtn; xtn->ecb.clear = clear_xtn;

View File

@ -27,12 +27,15 @@
extern "C" { extern "C" {
#endif #endif
qse_awk_flt_t qse_awk_stdmathpow (qse_awk_t* awk, qse_awk_flt_t x, qse_awk_flt_t y); QSE_EXPORT qse_awk_flt_t qse_awk_stdmathpow (qse_awk_t* awk, qse_awk_flt_t x, qse_awk_flt_t y);
qse_awk_flt_t qse_awk_stdmathmod (qse_awk_t* awk, qse_awk_flt_t x, qse_awk_flt_t y); QSE_EXPORT qse_awk_flt_t qse_awk_stdmathmod (qse_awk_t* awk, qse_awk_flt_t x, qse_awk_flt_t y);
void* qse_awk_stdmodopen (qse_awk_t* awk, const qse_awk_mod_spec_t* spec); QSE_EXPORT int qse_awk_stdmodstartup (qse_awk_t* awk);
void qse_awk_stdmodclose (qse_awk_t* awk, void* handle); QSE_EXPORT void qse_awk_stdmodshutdown (qse_awk_t* awk);
void* qse_awk_stdmodsym (qse_awk_t* awk, void* handle, const qse_char_t* name);
QSE_EXPORT void* qse_awk_stdmodopen (qse_awk_t* awk, const qse_awk_mod_spec_t* spec);
QSE_EXPORT void qse_awk_stdmodclose (qse_awk_t* awk, void* handle);
QSE_EXPORT void* qse_awk_stdmodsym (qse_awk_t* awk, void* handle, const qse_char_t* name);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -441,8 +441,21 @@ static QSE_INLINE qse_ssize_t __send_file (
qse_fio_hnd_t fh; qse_fio_hnd_t fh;
fh = qse_fio_gethandle (HANDLE_TO_FIO(in_fd)); fh = qse_fio_gethandle (HANDLE_TO_FIO(in_fd));
#if defined(__FreeBSD__)
{
off_t nsent;
ret = sendfile (fh, out_fd, *offset, count, QSE_NULL, &nsent, 0);
if (ret == 0)
{
*offset += nsent;
ret = nsent;
}
else qse_httpd_seterrnum (httpd, SKERR_TO_ERRNUM());
}
#else
ret = sendfile (out_fd, fh, offset, count); ret = sendfile (out_fd, fh, offset, count);
if (ret <= -1) qse_httpd_seterrnum (httpd, SKERR_TO_ERRNUM()); if (ret <= -1) qse_httpd_seterrnum (httpd, SKERR_TO_ERRNUM());
#endif
return ret; return ret;
#elif defined(HAVE_SENDFILE64) #elif defined(HAVE_SENDFILE64)