Changeset 4322

Show
Ignore:
Timestamp:
03/12/09 15:53:52 (4 years ago)
Author:
Cyrus
Message:

nixio: FreeBSD compatibility #2

Location:
luci/trunk/libs/nixio/src
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • luci/trunk/libs/nixio/src/address.c

    r4287 r4322  
    2121#include <sys/socket.h> 
    2222#include <arpa/inet.h> 
     23#include <netinet/in.h> 
    2324#include <string.h> 
    2425#include <netdb.h> 
  • luci/trunk/libs/nixio/src/bind.c

    r4287 r4322  
    2121#include <sys/socket.h> 
    2222#include <arpa/inet.h> 
     23#include <netinet/in.h> 
    2324#include <sys/un.h> 
    2425#include <string.h> 
     
    2627#include <netdb.h> 
    2728#include <errno.h> 
    28 #include "nixio.h" 
    2929 
    3030/** 
  • luci/trunk/libs/nixio/src/file.c

    r4287 r4322  
    2626#include <sys/types.h> 
    2727#include <sys/stat.h> 
     28#include <sys/param.h> 
    2829 
    2930 
     
    210211static int nixio_file_sync(lua_State *L) { 
    211212    int fd = nixio__checkfd(L, 1); 
     213#ifndef BSD 
    212214    int meta = lua_toboolean(L, 2); 
    213215    return nixio__pstatus(L, (meta) ? !fsync(fd) : !fdatasync(fd)); 
     216#else 
     217    return nixio__pstatus(L, !fsync(fd)); 
     218#endif 
    214219} 
    215220 
  • luci/trunk/libs/nixio/src/io.c

    r4281 r4322  
    2424#include <sys/socket.h> 
    2525#include <arpa/inet.h> 
    26 #include "nixio.h" 
    27  
     26#include <netinet/in.h> 
    2827 
    2928 
  • luci/trunk/libs/nixio/src/splice.c

    r4312 r4322  
    2626#include <errno.h> 
    2727#include <unistd.h> 
     28 
     29#ifndef BSD 
    2830#include <sys/sendfile.h> 
     31#else 
     32#include <sys/types.h> 
     33#include <sys/socket.h> 
     34#include <sys/uio.h> 
     35#endif 
    2936 
    3037#ifdef _GNU_SOURCE 
     
    103110 */ 
    104111static int nixio_sendfile(lua_State *L) { 
    105     int sockfd = nixio__checksockfd(L); 
     112    int sock = nixio__checksockfd(L); 
    106113    int infd = nixio__checkfd(L, 2); 
    107114    size_t len = luaL_checkinteger(L, 3); 
     115    off_t spliced; 
    108116 
    109     long spliced = sendfile(sockfd, infd, NULL, len); 
     117#ifndef BSD 
     118    do { 
     119        spliced = sendfile(sock, infd, NULL, len); 
     120    } while (spliced == -1 && errno == EINTR); 
    110121 
    111     if (spliced < 0) { 
     122    if (spliced == -1) { 
    112123        return nixio__perror(L); 
    113124    } 
     125#else 
     126    int r; 
     127    const off_t offset = lseek(infd, 0, SEEK_CUR); 
     128 
     129    do { 
     130        r = sendfile(infd, sock, offset, len, NULL, &spliced, 0); 
     131    } while (r == -1 && errno == EINTR); 
     132 
     133    if (r == -1) { 
     134        return nixio__perror(L); 
     135    } 
     136#endif 
    114137 
    115138    lua_pushnumber(L, spliced);