diff --git a/qse/cmd/http/ursd.c b/qse/cmd/http/ursd.c index 5ccdfc65..0439f547 100644 --- a/qse/cmd/http/ursd.c +++ b/qse/cmd/http/ursd.c @@ -183,7 +183,12 @@ static qse_sck_hnd_t open_server_socket (int proto, const qse_nwad_t* bindnwad) skad_len = qse_nwadtoskad (bindnwad, &skad); family = qse_skadfamily(&skad); + +#if defined(IPPROTO_SCTP) type = (proto == IPPROTO_SCTP)? SOCK_SEQPACKET: SOCK_DGRAM; +#else + type = SOCK_DGRAM; +#endif s = socket (family, type, proto); if (!qse_isvalidsckhnd(s)) @@ -221,9 +226,10 @@ static qse_sck_hnd_t open_server_socket (int proto, const qse_nwad_t* bindnwad) } bind_ok: + #if defined(IPPROTO_SCTP) if (proto == IPPROTO_SCTP) { - #if defined(SOL_SCTP) + #if defined(SOL_SCTP) struct sctp_initmsg im; struct sctp_paddrparams hb; @@ -244,7 +250,7 @@ bind_ok: hb.spp_pathmaxrxt = 1; if (setsockopt (s, SOL_SCTP, SCTP_PEER_ADDR_PARAMS, &hb, QSE_SIZEOF(hb)) <= -1) goto oops; - #endif + #endif if (listen (s, 99) <= -1) { @@ -252,6 +258,7 @@ bind_ok: goto oops; } } + #endif return s; diff --git a/qse/lib/awk/mod-math.c b/qse/lib/awk/mod-math.c index 5ea986c7..0c3de629 100644 --- a/qse/lib/awk/mod-math.c +++ b/qse/lib/awk/mod-math.c @@ -155,7 +155,45 @@ static qse_awk_flt_t math_round (qse_awk_t* awk, qse_awk_flt_t x) #elif defined(HAVE_ROUNDF) return roundf (x); #else - #error ### no round function available ### + + qse_flt_t f, d; + + f = math_floor (awk, x); + d = x - f; /* get fraction */ + + if (d > (qse_awk_flt_t)0.5) + { + /* round up to the nearest */ + f = f + (qse_awk_flt_t)1.0; + } + else if (d == (qse_awk_flt_t)0.5) + { + #if 1 + /* round half away from zero */ + if (x >= 0) + { + f = x + (qse_awk_flt_t)0.5; + } + else + { + f = x - (qse_awk_flt_t)0.5; + } + #else + /* round half to even - C99's rint() does this, i guess. */ + d = f - (qse_awk_flt_t)2.0 * math_floor(awk, f * (qse_awk_flt_t)0.5); + if (d == (qse_awk_flt_t)1.0) f = f + (qse_awk_flt_t)1.0; + #endif + } + + /* this implementation doesn't keep the signbit for -0.0. + * The signbit() function defined in C99 may get used to + * preserve the sign bit. but this is a fall-back rountine + * for a system without round also defined in C99. + * don't get annoyed by the lost sign bit for the value of 0.0. + */ + + return f; + #endif } diff --git a/qse/lib/http/httpd-std-urs.h b/qse/lib/http/httpd-std-urs.h index a9bdf6a2..62bfa948 100644 --- a/qse/lib/http/httpd-std-urs.h +++ b/qse/lib/http/httpd-std-urs.h @@ -119,7 +119,11 @@ static int urs_open (qse_httpd_t* httpd, qse_httpd_urs_t* urs) httpd->opt.rcb.logact (httpd, &msg); } +#if defined(IPPROTO_SCTP) type = (proto == IPPROTO_SCTP)? SOCK_SEQPACKET: SOCK_DGRAM; +#else + type = SOCK_DGRAM; +#endif urs->handle[0].i = open_udp_socket (httpd, AF_INET, type, proto); #if defined(AF_INET6) diff --git a/qse/lib/http/httpd-std.c b/qse/lib/http/httpd-std.c index b1b5ce4b..8711539d 100644 --- a/qse/lib/http/httpd-std.c +++ b/qse/lib/http/httpd-std.c @@ -430,8 +430,11 @@ static QSE_INLINE qse_ssize_t __send_file ( #endif size_t xfer; ssize_t ret; + qse_fio_hnd_t fh; - vec.sfv_fd = in_fd.i; + fh = qse_fio_gethandle(in_fd.ptr); + + vec.sfv_fd = fh; vec.sfv_flag = 0; if (offset) { @@ -439,7 +442,7 @@ static QSE_INLINE qse_ssize_t __send_file ( } else { - vec.sfv_off = QSE_LSEEK (in_fd.i, 0, SEEK_CUR); + vec.sfv_off = QSE_LSEEK (fh, 0, SEEK_CUR); if (vec.sfv_off == (off_t)-1) return (qse_ssize_t)-1; } vec.sfv_len = count; @@ -739,9 +742,10 @@ static qse_sck_hnd_t open_udp_socket (qse_httpd_t* httpd, int domain, int type, if (set_socket_nonblock (httpd, fd, 1) <= -1) goto oops; + #if defined(IPPROTO_SCTP) if (proto == IPPROTO_SCTP) { - #if defined(SOL_SCTP) + #if defined(SOL_SCTP) struct sctp_initmsg im; struct sctp_paddrparams hb; @@ -758,8 +762,9 @@ static qse_sck_hnd_t open_udp_socket (qse_httpd_t* httpd, int domain, int type, hb.spp_pathmaxrxt = 1; if (setsockopt (fd, SOL_SCTP, SCTP_PEER_ADDR_PARAMS, &hb, QSE_SIZEOF(hb)) <= -1) goto oops; - #endif + #endif } + #endif return fd;