* harbour/include/hbstack.h
+ added socket error codes to HB_IOERRORS
* harbour/include/Makefile
+ harbour/include/hbsocket.ch
+ harbour/include/hbsocket.h
* harbour/source/rtl/Makefile
+ harbour/source/rtl/hbsocket.c
+ added new BSD socket functions: hb_socket*(). They should be quite
close to low level C socket interface with few modifications which
help to hide some platform differences. Unfortunately we do not use
autoconf so I had to arbitrary set which features are available
on some platforms. In practice it means that it reduces portability
to older OS-es, i.e. it should work with current Linux versions
but it will not without some modifications in macros used to control
supported features with older Linuxes using kernel 2.2 or 2.0.
The same can happen with other *nix ports like Darwin, SunOS, HP-UX
or with different versions of some Windows compilers. I also do not
know which functionality is available in OS2 GCC ports and I would
like to ask OS2 users to make tests and disable not working features.
We also need tests with HP-UX, Darwin and SunOS.
IP6 support is enabled only in *nixes. If Windows users are interested
in IP6 then please add support for it. Most of Windows compilers do
not support standard POSIX functions so I do not want to make it
myself using unknown for me API without testing.
In *nix builds PF_UNIX/PF_LOCAL sockets are also supported.
Support for other socket types can be easy added if someone is
interested in them.
The constant values used in hbsocket.ch are equal to original BSD
socket definitions. If it's necessary then it's possible to enable
their translation inside hbsocket.c code though I do not think we
will find such OS.
The list of hb_socket*() functions was designed to cover all existing
functionality in hbinet.c and socket.c. Most of functions supports
timeout parameter what effectively allows to hide direct select()
usage.
Please make test with real applications and report any problems
with hb_inet*() functions you will find.
* harbour/source/vm/hvm.c
* minor cleanup
* harbour/source/rtl/hbi18n1.c
* cleaned variable name
* harbour/source/rtl/hbinet.c
* harbour/examples/uhttpd2/socket.c
* harbour/contrib/hbssl/hbssl.c
* updated to use hb_socket*() functions
* harbour/include/hbextern.ch
* enabled HB_INET*() functions in DOS builds - they will simply return
errors
- harbour/include/hbapinet.h
- removed old header file
* harbour/source/pp/ppcore.c
! modified ENDTEXT marker to work also with comments in the same line
It's more closer to Clipper though intentionally we are not fully
CA-Cl*pper compatible here.
120 lines
6.6 KiB
C
120 lines
6.6 KiB
C
/*
|
|
* $Id$
|
|
*/
|
|
|
|
/*
|
|
* Harbour Project source code:
|
|
* socket C API
|
|
*
|
|
* Copyright 2009 Przemyslaw Czerpak <druzus / at / priv.onet.pl>
|
|
* www - http://www.harbour-project.org
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
* any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this software; see the file COPYING. If not, write to
|
|
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
|
|
*
|
|
* As a special exception, the Harbour Project gives permission for
|
|
* additional uses of the text contained in its release of Harbour.
|
|
*
|
|
* The exception is that, if you link the Harbour libraries with other
|
|
* files to produce an executable, this does not by itself cause the
|
|
* resulting executable to be covered by the GNU General Public License.
|
|
* Your use of that executable is in no way restricted on account of
|
|
* linking the Harbour library code into it.
|
|
*
|
|
* This exception does not however invalidate any other reasons why
|
|
* the executable file might be covered by the GNU General Public License.
|
|
*
|
|
* This exception applies only to the code released by the Harbour
|
|
* Project under the name Harbour. If you copy code from other
|
|
* Harbour Project or Free Software Foundation releases into a copy of
|
|
* Harbour, as the General Public License permits, the exception does
|
|
* not apply to the code that you add in this way. To avoid misleading
|
|
* anyone as to the status of such modified files, you must delete
|
|
* this exception notice from them.
|
|
*
|
|
* If you write modifications of your own for Harbour, it is your choice
|
|
* whether to permit this exception to apply to your modifications.
|
|
* If you do not wish that, delete this exception notice.
|
|
*
|
|
*/
|
|
|
|
#ifndef HB_SOCK_H_
|
|
#define HB_SOCK_H_
|
|
|
|
#include "hbapi.h"
|
|
#include "hbsocket.ch"
|
|
|
|
HB_EXTERN_BEGIN
|
|
|
|
#if defined( HB_OS_WIN ) && ! defined( HB_OS_UNIX_COMPATIBLE )
|
|
typedef HB_PTRUINT HB_SOCKET_T;
|
|
#else
|
|
typedef int HB_SOCKET_T;
|
|
#endif
|
|
|
|
typedef HB_SOCKET_T ( * HB_SOCK_FUNC )( PHB_ITEM );
|
|
|
|
#define HB_NO_SOCKET ( ( HB_SOCKET_T ) -1 )
|
|
|
|
HB_EXPORT extern int hb_socketInit( void );
|
|
HB_EXPORT extern void hb_socketCleanup( void );
|
|
HB_EXPORT extern int hb_socketGetError( void );
|
|
HB_EXPORT extern int hb_socketGetOsError( void );
|
|
HB_EXPORT extern const char * hb_socketErrorStr( int iError );
|
|
HB_EXPORT extern int hb_socketGetAddrFamilly( const void * pSockAddr, unsigned len );
|
|
HB_EXPORT extern BOOL hb_socketLocalAddr( void ** pSockAddr, unsigned * puiLen, const char * szAddr );
|
|
HB_EXPORT extern BOOL hb_socketInetAddr( void ** pSockAddr, unsigned * puiLen, const char * szAddr, int iPort );
|
|
HB_EXPORT extern BOOL hb_socketInet6Addr( void ** pSockAddr, unsigned * puiLen, const char * szAddr, int iPort );
|
|
HB_EXPORT extern char * hb_socketAddrGetName( const void * pSockAddr, unsigned len );
|
|
HB_EXPORT extern char * hb_socketResolveAddr( const char * szAddr, int af );
|
|
HB_EXPORT extern PHB_ITEM hb_socketGetHosts( const char * szAddr, int af );
|
|
HB_EXPORT extern PHB_ITEM hb_socketGetAliases( const char * szAddr, int af );
|
|
HB_EXPORT extern int hb_socketAddrGetPort( const void * pSockAddr, unsigned len );
|
|
HB_EXPORT extern BOOL hb_socketAddrFromItem( void ** pSockAddr, unsigned * puiLen, PHB_ITEM pAddrItm );
|
|
HB_EXPORT extern PHB_ITEM hb_socketAddrToItem( const void * pSockAddr, unsigned len );
|
|
HB_EXPORT extern int hb_socketGetSockName( HB_SOCKET_T sd, void ** pSockAddr, unsigned * puiLen );
|
|
HB_EXPORT extern int hb_socketGetPeerName( HB_SOCKET_T sd, void ** pSockAddr, unsigned * puiLen );
|
|
HB_EXPORT extern HB_SOCKET_T hb_socketOpen( int domain, int type, int protocol );
|
|
HB_EXPORT extern int hb_socketClose( HB_SOCKET_T sd );
|
|
HB_EXPORT extern int hb_socketShutdown( HB_SOCKET_T sd, int iMode );
|
|
HB_EXPORT extern int hb_socketBind( HB_SOCKET_T sd, const void * pSockAddr, unsigned uiLen );
|
|
HB_EXPORT extern int hb_socketListen( HB_SOCKET_T sd, int iBacklog );
|
|
HB_EXPORT extern HB_SOCKET_T hb_socketAccept( HB_SOCKET_T sd, void ** pSockAddr, unsigned * puiLen, HB_LONG timeout );
|
|
HB_EXPORT extern int hb_socketConnect( HB_SOCKET_T sd, const void * pSockAddr, unsigned uiLen, HB_LONG timeout );
|
|
HB_EXPORT extern long hb_socketSend( HB_SOCKET_T sd, const void * data, long len, int flags, HB_LONG timeout );
|
|
HB_EXPORT extern long hb_socketSendTo( HB_SOCKET_T sd, const void * data, long len, int flags, const void * pSockAddr, unsigned uiSockLen, HB_LONG timeout );
|
|
HB_EXPORT extern long hb_socketRecv( HB_SOCKET_T sd, void * data, long len, int flags, HB_LONG timeout );
|
|
HB_EXPORT extern long hb_socketRecvFrom( HB_SOCKET_T sd, void * data, long len, int flags, void ** pSockAddr, unsigned * puiSockLen, HB_LONG timeout );
|
|
HB_EXPORT extern int hb_socketSetBlockingIO( HB_SOCKET_T sd, BOOL fBlocking );
|
|
HB_EXPORT extern int hb_socketSetReuseAddr( HB_SOCKET_T sd, BOOL fReuse );
|
|
HB_EXPORT extern int hb_socketSetKeepAlive( HB_SOCKET_T sd, BOOL fKeepAlive );
|
|
HB_EXPORT extern int hb_socketSetBroadcast( HB_SOCKET_T sd, BOOL fBroadcast );
|
|
HB_EXPORT extern int hb_socketSetSndBufSize( HB_SOCKET_T sd, int iSize );
|
|
HB_EXPORT extern int hb_socketSetRcvBufSize( HB_SOCKET_T sd, int iSize );
|
|
HB_EXPORT extern int hb_socketGetRcvBufSize( HB_SOCKET_T sd, int * piSize );
|
|
HB_EXPORT extern int hb_socketGetSndBufSize( HB_SOCKET_T sd, int * piSize );
|
|
HB_EXPORT extern int hb_socketSetMulticast( HB_SOCKET_T sd, int af, const char * szAddr );
|
|
HB_EXPORT extern int hb_socketSelectRead( HB_SOCKET_T sd, HB_LONG timeout );
|
|
HB_EXPORT extern int hb_socketSelectWrite( HB_SOCKET_T sd, HB_LONG timeout );
|
|
HB_EXPORT extern int hb_socketSelectWriteEx( HB_SOCKET_T sd, HB_LONG timeout );
|
|
HB_EXPORT extern int hb_socketSelect( PHB_ITEM pArrayRD, BOOL fSetRD,
|
|
PHB_ITEM pArrayWR, BOOL fSetWR,
|
|
PHB_ITEM pArrayEX, BOOL fSetEX,
|
|
HB_LONG timeout, HB_SOCK_FUNC pFunc );
|
|
|
|
HB_EXTERN_END
|
|
|
|
#endif /* HB_SOCK_H_ */
|