[Common-cvs] netio/pub/platform/posix netdrv.h, NONE, 1.1 nettypes.h, NONE, 1.1 sockimp.h, NONE, 1.1

[Common-cvs] netio/pub/platform/posix netdrv.h, NONE, 1.1 nettypes.h, NONE, 1.1 sockimp.h, NONE, 1.1

tmarshall at helixcommunity.org tmarshall at helixcommunity.org
Tue Apr 20 09:46:33 PDT 2004


Update of /cvsroot/common/netio/pub/platform/posix
In directory cvs-new:/tmp/cvs-serv24279/pub/platform/posix

Added Files:
	netdrv.h nettypes.h sockimp.h 
Log Message:
New network API: initial implementation.



--- NEW FILE: nettypes.h ---
#ifndef _NETTYPES_H
#define _NETTYPES_H

/*
 * This is the Posix implementation of the Helix network driver.  It is used
 * for all Unix platforms and Win32 platforms that use the select model (the
 * server).  It follows the standard BSD API pretty much as one would expect,
 * with the following exceptions:
 *
 *  - All socket addresses are sockaddr_storage.  The ss_family member implies
 *    the underlying type (sockaddr_un, sockaddr_in, sockaddr_in6) and length.
 *    If there is no IPv6 support on a particular platform, sockaddr_storage
 *    will most likely not be defined.  In this case, a generic definition is
 *    provided.
 *
 *  - Sockets are always nonblocking.  hx_socket() and hx_accept() should set
 *    O_NONBLOCK, FIONBIO or equivalent if necessary.
 *
 *  - Sockets always reuse addresses and ports (SO_REUSEADDR or equivalent)
 *    if available.
 *
 *  - All functions should retry in case of interruption (EINTR).
 *
 *  - hx_connect() is always nonblocking.  The return code is -1 for failure,
 *    0 for pending, and 1 for immediate success.
 *
 *  - Name resoluton... TDB
 *
 *  - hx_inet_pton() must accept address strings that are not terminated (maybe?)
 */

/*
 * Definitions for HX_SOCK, socklen_t, etc.
 *
 * Also defines:
 *   hx_htonl
 *   hx_ntohl
 *   hx_htons
 *   hx_ntohs
 *   hx_inet_ntop
 *   hx_inet_pton
 */

#define HX_SOCK_ERR int
#define HX_MAX_IOV 16
typedef struct iovec hx_iov;

#define hx_htonl htonl
#define hx_ntohl ntohl
#define hx_htons htons
#define hx_ntohs ntohs

#define hx_inet_ntop inet_ntop
#define hx_inet_pton inet_pton

// Some definitions to unify the minor differences in various platforms.
//XXXTDM: move some of these includes into netdrv.cpp?
#if defined(_UNIX)
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <sys/un.h>
#include <sys/uio.h>
#include <errno.h>
typedef int sockobj_t;
typedef int sockerr_t;
#define INVALID_SOCKET      -1
#define SOCKET_ERROR        -1
#define SOCKERR_NONE        0
#define SOCKERR_INTR        EINTR
#define SOCKERR_WOULDBLOCK  EAGAIN
#define SOCKERR_INPROGRESS  EINPROGRESS
#define SOCKERR_CONNRESET   EPIPE
#define SOCKERR_EOF         -1
/* NB: Platforms needing socklen_t include FreeBSD < 4.0 and Solaris < 8.0 */
#if defined(_FREEBSD2) || defined(_FREEBSD3) || defined(_SOLARIS26) || defined(_SOLARIS27)
typedef int socklen_t;
#endif
#if defined(_HPUX)
typedef int salen_t;
typedef void* saptr_t;
#else
typedef socklen_t salen_t;
typedef sockaddr* saptr_t;
#endif
#endif /* defined(_UNIX) */

#if defined(_WIN32)
/*
 * Win32 is very particular about winsock header files.  It is not possible
 * to include both winsock.h and winsock2.h.  The old winsock.h does not
 * have the definitions we need for IPv6 support and, furthermore, a few of
 * the constants have changed values between v1 and v2.  So we only support
 * v2 here.
 */
#if defined(_WINSOCKAPI_)
#if defined(USE_WINSOCK1) || !defined(_WINSOCK2API_)
#error "New network API requires winsock2"
#endif
#else /* !defined(_WINSOCKAPI_) */
#include <winsock2.h>
#endif /* defined(_WINSOCKAPI_) */
/*
 * There are two versions of winsock2.h (whee!)  The original one that comes
 * with VC6 does not have IPv6 definitions but the new one that comes with
 * VCdotnet does.  We detect the old version by testing whether IPPROTO_IPV6
 * is defined.  If not, try to use tpipv6.h from the Win2000 IPv6 package.
 */
#ifndef IPPROTO_IPV6
#include <ws2tcpip.h>
#include <tpipv6.h>
/*
 * XXXTDM
 * Terrible hack.  Win2000 tech preview was done before sin6_scope_id was
 * added to sockaddr_in6.  Therefore the size is too small (24 vs 28).  We
 * override it here to make this work with Winsock 2.2.
 *
 * We should just fail to compile with the Win2000 tech preview headers, but
 * I am too lazy to go find the dot-net Winsock 2.2 headers.
 */
struct hx_sockaddr_in6
{
    short   sin6_family;
    u_short sin6_port;
    u_long  sin6_flowinfo;
    struct  in_addr6 sin6_addr;
    u_long  sin6_scope_id;
};
#define sockaddr_in6 hx_sockaddr_in6
#endif
typedef SOCKET sockobj_t;
typedef int    sockerr_t;
typedef int    socklen_t;
typedef int    sa_family_t;
typedef int    ssize_t;
typedef UINT32 in_addr_t;
typedef UINT16 in_port_t;
//XXXTDM: how to implement local sockets in Win32?
struct sockaddr_un { sa_family_t sun_family; char sun_path[128]; };
struct iovec { void* iov_base; size_t iov_len; };
// INVALID_SOCKET defined in winsock.h
// SOCKET_ERROR defined in winsock.h
#define SOCKERR_NONE        0
#define SOCKERR_INTR        WSAEINTR
#define SOCKERR_WOULDBLOCK  WSAEWOULDBLOCK
#define SOCKERR_INPROGRESS  WSAEINPROGRESS
#define SOCKERR_CONNRESET   WSAECONNRESET
#define SOCKERR_EOF         0x7FFFFFFF
#define INET6_ADDRSTRLEN 46
int         inet_aton(const char* cp, struct in_addr* inp);
const char* inet_ntop(int af, const void* src, char* dst, socklen_t len);
int         inet_pton(int af, const char* src, void* dst);
#endif /* defined(_WIN32) */

// Some platforms have strange and/or outdated headers.
#ifndef INADDR_NONE
#define INADDR_NONE ((UINT32)0xFFFFFFFF)
#endif
#ifndef INADDR_ANY
#define INADDR_ANY  ((UINT32)0x00000000)
#endif

#ifndef AF_LOCAL
#define AF_LOCAL AF_UNIX
#endif
#ifndef SOL_IP
#define SOL_IP IPPROTO_IP
#endif
#ifndef SOL_UDP
#define SOL_UDP IPPROTO_UDP
#endif
#ifndef SOL_TCP
#define SOL_TCP IPPROTO_TCP
#endif
#ifndef SOL_IPV6
#define SOL_IPV6 IPPROTO_IPV6
#endif

typedef struct
{
    sockobj_t   sock;
    int         state;
    UINT32      evmask;
} HX_SOCK;

#define HX_SOCK_VALID(s) (s.sock != INVALID_SOCKET)

#endif /* ndef _NETTYPES_H */

--- NEW FILE: sockimp.h ---
/* ***** BEGIN LICENSE BLOCK *****
 * Version: RCSL 1.0/RPSL 1.0
 *
 * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved.
 *
 * The contents of this file, and the files included with this file, are
 * subject to the current version of the RealNetworks Public Source License
 * Version 1.0 (the "RPSL") available at
 * http://www.helixcommunity.org/content/rpsl unless you have licensed
 * the file under the RealNetworks Community Source License Version 1.0
 * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl,
 * in which case the RCSL will apply. You may also obtain the license terms
 * directly from RealNetworks.  You may not use this file except in
 * compliance with the RPSL or, if you have a valid RCSL with RealNetworks
 * applicable to this file, the RCSL.  Please see the applicable RPSL or
 * RCSL for the rights, obligations and limitations governing use of the
 * contents of the file.
 *
 * This file is part of the Helix DNA Technology. RealNetworks is the
 * developer of the Original Code and owns the copyrights in the portions
 * it created.
 *
 * This file, and the files included with this file, is distributed and made
 * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
 * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES,
 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
 *
 * Technology Compatibility Kit Test Suite(s) Location:
 *    http://www.helixcommunity.org/content/tck
 *
 * Contributor(s):
 *
 * ***** END LICENSE BLOCK ***** */

#ifndef _SOCKIMP_H
#define _SOCKIMP_H

#include "nettypes.h"

class CHXSockAddrLocal : public IHXSockAddr,
                         public IHXSockAddrLocal
{
private:    // Unimplemented
    CHXSockAddrLocal(const CHXSockAddrLocal&);
    CHXSockAddrLocal& operator=(CHXSockAddrLocal&);

public:
    CHXSockAddrLocal(void);
    CHXSockAddrLocal(const sockaddr_un* psa);
    // No need for a dtor
    // virtual ~CHXSockAddrLocal(void);

    STDMETHOD(QueryInterface)       (THIS_ REFIID riid, void** ppvObj);
    STDMETHOD_(ULONG32,AddRef)      (THIS);
    STDMETHOD_(ULONG32,Release)     (THIS);

    STDMETHOD_(HXSockFamily,GetFamily)      (void);
    STDMETHOD_(BOOL,IsEqual)                (THIS_ IHXSockAddr* pOther);

    STDMETHOD_(BOOL,Get)                    (THIS_ void* dst);
    STDMETHOD_(BOOL,Set)                    (THIS_ void* src);

    STDMETHOD(GetAddr)                      (THIS_ char* pBuf);
    STDMETHOD(SetAddr)                      (THIS_ const char* pBuf);

protected:
    INT32                       m_nRefCount;
    sockaddr_un                 m_addr;
};

class CHXSockAddrIN4 : public IHXSockAddr,
                       public IHXSockAddrIN4
{
private:    // Unimplemented
    CHXSockAddrIN4(const CHXSockAddrIN4&);
    CHXSockAddrIN4& operator=(CHXSockAddrIN4&);

public:
    CHXSockAddrIN4(void);
    CHXSockAddrIN4(const sockaddr_in* psa);
    // No need for a dtor
    // virtual ~CHXSockAddrIN4(void);

    STDMETHOD(QueryInterface)       (THIS_ REFIID riid, void** ppvObj);
    STDMETHOD_(ULONG32,AddRef)      (THIS);
    STDMETHOD_(ULONG32,Release)     (THIS);

    STDMETHOD_(HXSockFamily,GetFamily)      (void);
    STDMETHOD_(BOOL,IsEqual)                (THIS_ IHXSockAddr* pOther);

    STDMETHOD_(BOOL,Get)                    (THIS_ void* dst);
    STDMETHOD_(BOOL,Set)                    (THIS_ void* src);

    STDMETHOD(GetAddr)                      (THIS_ char* pBuf);
    STDMETHOD(SetAddr)                      (THIS_ const char* pBuf);
    STDMETHOD_(BOOL,IsEqualAddr)            (THIS_ IHXSockAddrIN4* pOther);
    STDMETHOD(MaskAddr)                     (THIS_ UINT32 nBits);
    STDMETHOD_(HXIN4AddrClass,GetAddrClass) (THIS);
    STDMETHOD(GetPort)                      (THIS_ char* pBuf);
    STDMETHOD(SetPort)                      (THIS_ const char* pBuf);
    STDMETHOD_(BOOL,IsEqualPort)            (THIS_ IHXSockAddrIN4* pOther);

protected:
    INT32                       m_nRefCount;
    sockaddr_in                 m_addr;
};

class CHXSockAddrIN6 : public IHXSockAddr,
                       public IHXSockAddrIN6
{
private:    // Unimplemented
    CHXSockAddrIN6(const CHXSockAddrIN6&);
    CHXSockAddrIN6& operator=(CHXSockAddrIN6&);

public:
    CHXSockAddrIN6(void);
    CHXSockAddrIN6(const sockaddr_in6* psa);
    // No need for a dtor
    // virtual ~CHXSockAddrIN6(void);

    STDMETHOD(QueryInterface)       (THIS_ REFIID riid, void** ppvObj);
    STDMETHOD_(ULONG32,AddRef)      (THIS);
    STDMETHOD_(ULONG32,Release)     (THIS);

    STDMETHOD_(HXSockFamily,GetFamily)      (void);
    STDMETHOD_(BOOL,IsEqual)                (THIS_ IHXSockAddr* pOther);

    STDMETHOD_(BOOL,Get)                    (THIS_ void* dst);
    STDMETHOD_(BOOL,Set)                    (THIS_ void* src);

    STDMETHOD(GetAddr)                      (THIS_ char* pBuf);
    STDMETHOD(GetFullAddr)                  (THIS_ char* pBuf);
    STDMETHOD(GetFullAddrZ)                 (THIS_ char* pBuf);
    STDMETHOD(ExtractIN4Addr)               (THIS_ IHXSockAddrIN4** ppAddr);
    STDMETHOD(SetAddr)                      (THIS_ const char* pBuf);
    STDMETHOD_(BOOL,IsEqualAddr)            (THIS_ IHXSockAddrIN6* pOther);
    STDMETHOD(MaskAddr)                     (THIS_ UINT32 nBits);
    STDMETHOD_(HXIN6AddrClass,GetAddrClass) (THIS);
    STDMETHOD(GetPort)                      (THIS_ char* pBuf);
    STDMETHOD(SetPort)                      (THIS_ const char* pBuf);
    STDMETHOD_(BOOL,IsEqualPort)            (THIS_ IHXSockAddrIN6* pOther);
    STDMETHOD_(UINT32,GetFlowInfo)          (THIS);
    STDMETHOD(SetFlowInfo)                  (THIS_ UINT32 uFlowInfo);
    STDMETHOD_(UINT32,GetScopeId)           (THIS);
    STDMETHOD(SetScopeId)                   (THIS_ UINT32 uScopeId);

protected:
    INT32                       m_nRefCount;
    sockaddr_in6                m_addr;
};

class CHXSocket;

class CHXSocketConnectEnumerator : public IHXSocketResponse
{
private:    // Unimplemented
    CHXSocketConnectEnumerator(const CHXSocketConnectEnumerator&);
    CHXSocketConnectEnumerator& operator=(const CHXSocketConnectEnumerator&);

public:
    CHXSocketConnectEnumerator(CHXSocket* pSock);
    virtual ~CHXSocketConnectEnumerator(void);

    void Init(UINT32 nVecLen, IHXSockAddr** ppAddrVec);

    STDMETHOD(QueryInterface)       (THIS_ REFIID riid, void** ppvObj);
    STDMETHOD_(ULONG32,AddRef)      (THIS);
    STDMETHOD_(ULONG32,Release)     (THIS);

    STDMETHOD(EventPending)         (THIS_ UINT32 uEvent, UINT32 uStatus);

private:
    void AttemptConnect(void);

protected:
    INT32                       m_nRefCount;
    CHXSocket*                  m_pSock;
    IHXSocketResponse*          m_pOldResponse;
    UINT32                      m_nVecLen;
    IHXSockAddr**               m_ppAddrVec;
    UINT32                      m_nIndex;
};

class CHXSocket : public IHXSocket
{
private:    // Unimplemented
    CHXSocket(const CHXSocket&);
    CHXSocket& operator=(const CHXSocket&);

public:
    CHXSocket(HXSockFamily f, HXSockType t, HXSockProtocol p);
    CHXSocket(HXSockFamily f, HXSockType t, HXSockProtocol p, HX_SOCK sock);
    virtual ~CHXSocket(void);

    IHXSocketResponse*  GetResponse(void);
    void                SetResponse(IHXSocketResponse*);
    void                OnEvent(UINT32 mask);
    void                ConnectEnumeratorDone(void);

    STDMETHOD(QueryInterface)       (THIS_ REFIID riid, void** ppvObj);
    STDMETHOD_(ULONG32,AddRef)      (THIS);
    STDMETHOD_(ULONG32,Release)     (THIS);

    STDMETHOD(Init)                 (THIS_ IHXSocketResponse* pResponse);

    STDMETHOD(Bind)                 (THIS_ IHXSockAddr* pAddr);
    STDMETHOD(ConnectToOne)         (THIS_ IHXSockAddr* pAddr);
    STDMETHOD(ConnectToAny)         (THIS_ UINT32 nVecLen, IHXSockAddr** ppAddrVec);
    STDMETHOD(GetLocalAddr)         (THIS_ IHXSockAddr* pAddr);
    STDMETHOD(GetPeerAddr)          (THIS_ IHXSockAddr* pAddr);

    STDMETHOD(SelectEvents)         (THIS_ UINT32 uEventMask);
    STDMETHOD(Peek)                 (THIS_ IHXBuffer* pBuf);
    STDMETHOD(Read)                 (THIS_ IHXBuffer* pBuf);
    STDMETHOD(Write)                (THIS_ IHXBuffer* pBuf);
    STDMETHOD(Close)                (THIS);

    STDMETHOD(Listen)               (THIS_ UINT32 uBackLog);
    STDMETHOD(Accept)               (THIS_ IHXSocket** ppNewSock,
                                           IHXSockAddr** ppSource);

    STDMETHOD(GetOption)            (THIS_ HXSockOpt name, UINT32* pval);
    STDMETHOD(SetOption)            (THIS_ HXSockOpt name, UINT32 val);

    STDMETHOD(ReadV)                (THIS_ UINT32 nVecLen, IHXBuffer** ppVec);
    STDMETHOD(ReadFrom)             (THIS_ IHXBuffer* pBuf, IHXSockAddr* pAddr);
    STDMETHOD(ReadFromV)            (THIS_ UINT32 nVecLen, IHXBuffer** ppVec,
                                           IHXSockAddr* pAddr);

    STDMETHOD(WriteV)               (THIS_ UINT32 nVecLen, IHXBuffer** ppVec);
    STDMETHOD(WriteTo)              (THIS_ IHXBuffer* pBuf, IHXSockAddr* pAddr);
    STDMETHOD(WriteToV)             (THIS_ UINT32 nVecLen, IHXBuffer** ppVec,
                                           IHXSockAddr* pAddr);

protected:
    INT32                       m_nRefCount;
    HXSockFamily                m_family;
    HXSockType                  m_type;
    HXSockProtocol              m_proto;
    HX_SOCK                     m_sock;
    IHXSocketResponse*          m_pResponse;
    CHXSocketConnectEnumerator* m_pEnumerator;
};

class CHXMulticastSocket : public CHXSocket,
                           public IHXMulticastSocket
{
private:    // Unimplemented
    CHXMulticastSocket(const CHXMulticastSocket&);
    CHXMulticastSocket& operator=(const CHXMulticastSocket&);

public:
    CHXMulticastSocket(void);
    // No need for a dtor
    // virtual ~CHXMulticastSocket(void);

    STDMETHOD(QueryInterface)       (THIS_ REFIID riid, void** ppvObj);
    STDMETHOD_(ULONG32,AddRef)      (THIS);
    STDMETHOD_(ULONG32,Release)     (THIS);

    STDMETHOD(JoinMulticastGroup)   (THIS_ IHXSockAddr* pAddr);
    STDMETHOD(LeaveMulticastGroup)  (THIS_ IHXSockAddr* pAddr);

protected:
    INT32                       m_nRefCount;
};

/*
 * The listening socket is just a wrapper around an IHXSocket.
 */
class CHXListeningSocket : public IHXListeningSocket,
                           public IHXSocketResponse
{
private:    // Unimplemented
    CHXListeningSocket(const CHXListeningSocket&);
    CHXListeningSocket& operator=(const CHXListeningSocket&);

public:
    CHXListeningSocket(HXSockFamily f, HXSockType t, HXSockProtocol p);
    virtual ~CHXListeningSocket(void);

    STDMETHOD(QueryInterface)       (THIS_ REFIID riid, void** ppvObj);
    STDMETHOD_(ULONG32,AddRef)      (THIS);
    STDMETHOD_(ULONG32,Release)     (THIS);

    STDMETHOD(Init)                 (THIS_ IHXListeningSocketResponse* pResponse);
    STDMETHOD(Listen)               (THIS_ IHXSockAddr* pAddr, UINT32 uBackLog);
    STDMETHOD(Accept)               (THIS_ IHXSocket** ppNewSock,
                                           IHXSockAddr** ppSource);
    STDMETHOD(Close)                (THIS);

    STDMETHOD(GetOption)            (THIS_ HXSockOpt name, UINT32* pval);
    STDMETHOD(SetOption)            (THIS_ HXSockOpt name, UINT32 val);

    STDMETHOD(EventPending)         (THIS_ UINT32 uEvent, UINT32 uStatus);

protected:
    INT32                       m_nRefCount;
    IHXListeningSocketResponse* m_pResponse;
    IHXSocket*                  m_pSock;
};

class CHXAddrInfo : public IHXAddrInfo
{
private:    // Unimplemented
    CHXAddrInfo(const CHXAddrInfo&);
    CHXAddrInfo& operator=(const CHXAddrInfo&);

public:
    CHXAddrInfo(void);
    // No need for a dtor
    // virtual ~CHXAddrInfo(void);

    STDMETHOD(QueryInterface)       (THIS_ REFIID riid, void** ppvObj);
    STDMETHOD_(ULONG32,AddRef)      (THIS);
    STDMETHOD_(ULONG32,Release)     (THIS);

    STDMETHOD_(UINT32,GetFlags)     (THIS);
    STDMETHOD(SetFlags)             (THIS_ UINT32 uFlags);
    STDMETHOD_(UINT32,GetFamily)    (THIS);
    STDMETHOD(SetFamily)            (THIS_ UINT32 uFamily);
    STDMETHOD_(UINT32,GetType)      (THIS);
    STDMETHOD(SetType)              (THIS_ UINT32 uType);
    STDMETHOD_(UINT32,GetProtocol)  (THIS);
    STDMETHOD(SetProtocol)          (THIS_ UINT32 uProtocol);

protected:
    INT32                       m_nRefCount;
};

class CHXResolve : public IHXResolve
{
private:    // Unimplemented
    CHXResolve(const CHXResolve&);
    CHXResolve& operator=(const CHXResolve&);

public:
    CHXResolve(void);
    // No need for a dtor
    // virtual ~CHXResolve(void);

    STDMETHOD(QueryInterface)       (THIS_ REFIID riid, void** ppvObj);
    STDMETHOD_(ULONG32,AddRef)      (THIS);
    STDMETHOD_(ULONG32,Release)     (THIS);

    STDMETHOD(GetAddrInfo)          (THIS_ const char* pNode, const char* pServ,
                                           IHXAddrInfo* pHints);
    STDMETHOD(FreeAddrInfo)         (THIS_ IHXSockAddr** ppInfoVec);

    STDMETHOD(GetNameInfo)          (THIS_ IHXSockAddr* pAddr, UINT32 uFlags,
                                           char* pNode, UINT32 uNodeLen,
                                           char* pServ, UINT32 uServLen);

protected:
    INT32                       m_nRefCount;
};

class CHXNetServices : public IHXNetServices
{
private:    // UNimplemented
    CHXNetServices(const CHXNetServices&);
    CHXNetServices& operator=(const CHXNetServices&);

public:
    CHXNetServices(void);
    // No need for a dtor
    // virtual ~CHXNetServices(void);

    void Init(void);

    STDMETHOD(QueryInterface)       (THIS_ REFIID riid, void** ppvObj);
    STDMETHOD_(ULONG32,AddRef)      (THIS);
    STDMETHOD_(ULONG32,Release)     (THIS);

    STDMETHOD_(UINT32,GetLastError) (THIS);
    STDMETHOD(CreateResolver)       (THIS_ IHXResolve** ppResolver);
    STDMETHOD(CreateSockAddr)       (THIS_ HXSockFamily f,
                                           IHXSockAddr** ppAddr);
    STDMETHOD(CreateListeningSocket)(THIS_ HXSockFamily f, HXSockType t, HXSockProtocol p,
                                           IHXListeningSocket** ppSock);
    STDMETHOD(CreateSocket)         (THIS_ HXSockFamily f, HXSockType t, HXSockProtocol p,
                                           IHXSocket** ppSock);

protected:
    INT32                       m_nRefCount;
};

#endif /* ndef _SOCKIMP_H */

--- NEW FILE: netdrv.h ---
#ifndef _NETDRV_H
#define _NETDRV_H

/*
 * This is the Posix implementation of the Helix network driver.  It is used
 * for all Unix platforms and Win32 platforms that use the select model (the
 * server).  It follows the standard BSD API pretty much as one would expect,
 * with the following exceptions:
 *
 *  - All socket addresses are sockaddr_storage.  The ss_family member implies
 *    the underlying type (sockaddr_un, sockaddr_in, sockaddr_in6) and length.
 *    If there is no IPv6 support on a particular platform, sockaddr_storage
 *    will most likely not be defined.  In this case, a generic definition is
 *    provided.
 *
 *  - Sockets are always nonblocking.  hx_socket() and hx_accept() should set
 *    O_NONBLOCK, FIONBIO or equivalent if necessary.
 *
 *  - Sockets always reuse addresses and ports (SO_REUSEADDR or equivalent)
 *    if available.
 *
 *  - All functions should retry in case of interruption (EINTR).
 *
 *  - hx_connect() is always nonblocking.  The return code is -1 for failure,
 *    0 for pending, and 1 for immediate success.
 *
 *  - Name resoluton... TDB
 *
 *  - hx_inet_pton() must accept address strings that are not terminated (maybe?)
 */

#include "nettypes.h"

/* Socket states are used to generate proper event notifications */
#define HX_SOCK_STATE_NONE          0
#define HX_SOCK_STATE_NORMAL        1
#define HX_SOCK_STATE_CONNECTING    2
#define HX_SOCK_STATE_LISTENING     3

extern const HX_SOCK HX_SOCK_NONE;

HX_SOCK_ERR hx_lastsockerror(void);

int hx_socket(HX_SOCK* s, int af, int type, int proto);
int hx_accept(HX_SOCK* s, HX_SOCK* snew, sockaddr_storage* addr);

int hx_close(HX_SOCK* s);

int hx_bind(HX_SOCK* s, const sockaddr_storage* addr);
int hx_connect(HX_SOCK* s, const sockaddr_storage* addr);
int hx_listen(HX_SOCK* s, UINT32 backlog);
int hx_getsockaddr(HX_SOCK* s, sockaddr_storage* addr);
int hx_getpeeraddr(HX_SOCK* s, sockaddr_storage* addr);

/* NB: no ioctls are implemented */
int hx_getsockopt(HX_SOCK* s, UINT32 name, UINT32* valp);
int hx_setsockopt(HX_SOCK* s, UINT32 name, UINT32 val);

int hx_peek(HX_SOCK* s, void* buf, size_t len);
int hx_read(HX_SOCK* s, void* buf, size_t len);
int hx_readv(HX_SOCK* s, UINT32 vlen, const hx_iov* iov);
int hx_readfrom(HX_SOCK* s, void* buf, size_t len,
                    sockaddr_storage* addr);
int hx_readfromv(HX_SOCK* s, UINT32 vlen, const hx_iov* iov,
                    sockaddr_storage* addr);
int hx_write(HX_SOCK* s, const void* buf, size_t len);
int hx_writev(HX_SOCK* s, UINT32 vlen, const hx_iov* iov);
int hx_writeto(HX_SOCK* s, const void* buf, size_t len,
                    const sockaddr_storage* addr);
int hx_writetov(HX_SOCK* s, UINT32 vlen, const hx_iov* iov,
                    const sockaddr_storage* addr);

#endif /* ndef _NETDRV_H */




More information about the Common-cvs mailing list
 

Site Map   |   Terms of Use   |   Privacy Policy   |   Contact Us

Copyright © 1995-2007 RealNetworks, Inc. All rights reserved. RealNetworks and Helix are trademarks of RealNetworks.
All other trademarks or registered trademarks are the property of their respective holders.