/*
* Copyright (c) 2002-2011 by XMLVM.org
*
* Project Info: http://www.xmlvm.org
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library 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 Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*/
#include <fcntl.h>
#include <errno.h>
#include <sys/poll.h>
//#include <sys/types.h>
//#include <sys/socket.h>
//#include "java_io_FileDescriptor.h"
//#include "java_net_SocketException.h"
//#include "java_lang_Thread.h"
#include "xmlvm.h"
#include "xmlvm-hy.h"
#include "xmlvm-sock.h"
#include "java_lang_String.h"
#include "java_io_FileDescriptor.h"
#include "java_net_InetAddress.h"
#include "java_net_Inet6Address.h"
#define MAX_RETRIES 50
#define INVALID_SOCKET (hysocket_t) -1
#if NO_R
/*use a mutex if the gethostbyaddr, gethostbyname calls are not threadsafe*/
MUTEX hostentLock = PTHREAD_MUTEX_INITIALIZER;
#endif /*NO_R */
const char* hysock_error_message ()
{
return hyerror_last_error_message ();
}
char* netLookupErrorString (I_32 anErrorNum)
{
switch (anErrorNum)
{
case HYPORT_ERROR_SOCKET_BADSOCKET:
return "Bad socket";
case HYPORT_ERROR_SOCKET_NOTINITIALIZED:
return "Socket library uninitialized";
case HYPORT_ERROR_SOCKET_BADAF:
return "Bad address family";
case HYPORT_ERROR_SOCKET_BADPROTO:
return "Bad protocol";
case HYPORT_ERROR_SOCKET_BADTYPE:
return "Bad type";
case HYPORT_ERROR_SOCKET_SYSTEMBUSY:
return "System busy handling requests";
case HYPORT_ERROR_SOCKET_SYSTEMFULL:
return "Too many sockets allocated";
case HYPORT_ERROR_SOCKET_NOTCONNECTED:
return "Socket is not connected";
case HYPORT_ERROR_SOCKET_INTERRUPTED:
return "The call was cancelled";
case HYPORT_ERROR_SOCKET_TIMEOUT:
return "The operation timed out";
case HYPORT_ERROR_SOCKET_CONNRESET:
return "The connection was reset";
case HYPORT_ERROR_SOCKET_WOULDBLOCK:
return "The socket is marked as nonblocking operation would block";
case HYPORT_ERROR_SOCKET_ADDRNOTAVAIL:
return "The address is not available";
case HYPORT_ERROR_SOCKET_ADDRINUSE:
return "The address is already in use";
case HYPORT_ERROR_SOCKET_NOTBOUND:
return "The socket is not bound";
case HYPORT_ERROR_SOCKET_UNKNOWNSOCKET:
return "Resolution of the FileDescriptor to socket failed";
case HYPORT_ERROR_SOCKET_INVALIDTIMEOUT:
return "The specified timeout is invalid";
case HYPORT_ERROR_SOCKET_FDSETFULL:
return "Unable to create an FDSET";
case HYPORT_ERROR_SOCKET_TIMEVALFULL:
return "Unable to create a TIMEVAL";
case HYPORT_ERROR_SOCKET_REMSOCKSHUTDOWN:
return "The remote socket has shutdown gracefully";
case HYPORT_ERROR_SOCKET_NOTLISTENING:
return "Listen() was not invoked prior to accept()";
case HYPORT_ERROR_SOCKET_NOTSTREAMSOCK:
return "The socket does not support connection-oriented service";
case HYPORT_ERROR_SOCKET_ALREADYBOUND:
return "The socket is already bound to an address";
case HYPORT_ERROR_SOCKET_NBWITHLINGER:
return "The socket is marked non-blocking & SO_LINGER is non-zero";
case HYPORT_ERROR_SOCKET_ISCONNECTED:
return "The socket is already connected";
case HYPORT_ERROR_SOCKET_NOBUFFERS:
return "No buffer space is available";
case HYPORT_ERROR_SOCKET_HOSTNOTFOUND:
return "Authoritative Answer Host not found";
case HYPORT_ERROR_SOCKET_NODATA:
return "Valid name, no data record of requested type";
case HYPORT_ERROR_SOCKET_BOUNDORCONN:
return "The socket has not been bound or is already connected";
case HYPORT_ERROR_SOCKET_OPNOTSUPP:
ret