/*----------------------------------------------------------------------* rtp_wfile_setcwd *----------------------------------------------------------------------*/ int rtp_wfile_setcwd (unsigned short * name) { #if (_WIN32_WINNT) >= 0x0400 #ifdef RTP_DEBUG int result; /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ SetLastError (0); #endif name = _rtp_unicode_name_to_winname (name); if (_wchdir ((const unsigned short *)name) != 0) { #ifdef RTP_DEBUG result = GetLastError(); RTP_DEBUG_OUTPUT_STR("rtp_wfile_setcwd: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } return (0); #endif return (-1); }
/*----------------------------------------------------------------------* _rtp_sig_semaphore_clear *----------------------------------------------------------------------*/ void _rtp_sig_semaphore_clear (RTP_HANDLE semHandle) { #ifdef LINUXTOBEIMPLEMENTED DWORD result; #ifdef RTP_DEBUG int err; /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ SetLastError (0); #endif while ((result = WaitForSingleObject((HANDLE)semHandle, 0)) == WAIT_OBJECT_0) { ; } #ifdef RTP_DEBUG if (result == WAIT_FAILED) { err = GetLastError(); RTP_DEBUG_OUTPUT_STR("rtp_sig_semaphore_clear: error returned "); RTP_DEBUG_OUTPUT_INT(err); RTP_DEBUG_OUTPUT_STR(".\n"); } #endif #endif }
/*----------------------------------------------------------------------* _rtp_sig_semaphore_wait *----------------------------------------------------------------------*/ int _rtp_sig_semaphore_wait (RTP_HANDLE semHandle) { #ifdef LINUXTOBEIMPLEMENTED #ifdef RTP_DEBUG int err; /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ SetLastError (0); #endif if (WaitForSingleObject((HANDLE)semHandle, INFINITE) == WAIT_FAILED) { #ifdef RTP_DEBUG err = GetLastError(); RTP_DEBUG_OUTPUT_STR("rtp_sig_semaphore_wait: error returned "); RTP_DEBUG_OUTPUT_INT(err); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } return (0); #else return (0); #endif }
/*----------------------------------------------------------------------* rtp_net_socket_stream *----------------------------------------------------------------------*/ int rtp_net_socket_stream (RTP_HANDLE *sockHandle) { int sock; #ifdef RTP_DEBUG int result; /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ set_errno (0); #endif sock = socket(AF_INET, SOCK_STREAM, 0); if (sock < 0) { *sockHandle = ((RTP_HANDLE)-1); #ifdef RTP_DEBUG result = xn_getlasterror(); RTP_DEBUG_OUTPUT_STR("rtp_net_socket_stream: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } *sockHandle = (RTP_HANDLE) sock; return (0); }
/*----------------------------------------------------------------------* rtp_net_setkeepalive *----------------------------------------------------------------------*/ int rtp_net_setkeepalive (RTP_HANDLE sockHandle, unsigned int onBool) { #ifdef LINUXTOBEIMPLEMENTED #ifdef RTP_DEBUG int result; /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ WSASetLastError (0); #endif if ( setsockopt((SOCKET) sockHandle, SOL_SOCKET, SO_KEEPALIVE, (char *) &onBool, sizeof (int)) == SOCKET_ERROR ) { #ifdef RTP_DEBUG result = WSAGetLastError(); RTP_DEBUG_OUTPUT_STR("rtp_net_setkeepalive: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } return (0); #else return (0); #endif }
/*----------------------------------------------------------------------* rtp_net_getntoread *----------------------------------------------------------------------*/ int rtp_net_getntoread (RTP_HANDLE sockHandle, unsigned long * nToRead) { unsigned long arg; #ifdef RTP_DEBUG int result; /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ set_errno (0); #endif if (ioctlsocket((int) sockHandle, FIONREAD, &arg) != 0) { #ifdef RTP_DEBUG result = xn_getlasterror(); RTP_DEBUG_OUTPUT_STR("rtp_net_getntoread: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } *nToRead = arg; return (0); }
/*----------------------------------------------------------------------* rtp_net_setblocking *----------------------------------------------------------------------*/ int rtp_net_setblocking (RTP_HANDLE sockHandle, unsigned int onBool) { unsigned long arg; #ifdef RTP_DEBUG int result; /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ set_errno (0); #endif arg = (unsigned long)(!onBool); if (ioctlsocket((int) sockHandle, FIONBIO, &arg) != 0) { #ifdef RTP_DEBUG result = xn_getlasterror(); RTP_DEBUG_OUTPUT_STR("rtp_net_setblocking: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } return (0); }
/*----------------------------------------------------------------------* rtp_net_socket_datagram *----------------------------------------------------------------------*/ int rtp_net_socket_datagram (RTP_HANDLE *sockHandle) { int sock; sock = socket(PF_INET, SOCK_DGRAM, 0); if (sock == -1) { int errVal = _rtp_get_last_socket_error(sockHandle); *sockHandle = ((RTP_HANDLE)-1); #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_net_socket_datagram: error returned "); RTP_DEBUG_OUTPUT_INT(errVal); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } *sockHandle = (RTP_HANDLE) sock; rtpnetOpenSockets++; return (0); }
/*----------------------------------------------------------------------* rtp_net_setmcastttl *----------------------------------------------------------------------*/ int rtp_net_setmcastttl(RTP_HANDLE sockHandle, int ttl) { #ifdef LINUXTOBEIMPLEMENTED int result; #ifdef RTP_DEBUG /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ WSASetLastError (0); #endif result = setsockopt( sockHandle, IPPROTO_IP, IP_MULTICAST_TTL, (char *) &ttl, sizeof (int)); if (result != 0) { #ifdef RTP_DEBUG result = WSAGetLastError(); RTP_DEBUG_OUTPUT_STR("rtp_net_setmembership: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } return (0); #else return (0); #endif }
/*----------------------------------------------------------------------* rtp_net_setmcastttl *----------------------------------------------------------------------*/ int rtp_net_setmcastttl(RTP_HANDLE sockHandle, int ttl) { int result; #ifdef RTP_DEBUG /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ set_errno (0); #endif result = setsockopt( sockHandle, IPPROTO_IP, IP_MULTICAST_TTL, (char *) &ttl, sizeof (int)); if (result != 0) { #ifdef RTP_DEBUG result = xn_getlasterror(); RTP_DEBUG_OUTPUT_STR("rtp_net_setmcastttl: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } return (0); }
/*----------------------------------------------------------------------* rtp_wfile_gnext *----------------------------------------------------------------------*/ int rtp_wfile_gnext (void * dirobj) { #if (_WIN32_WINNT) >= 0x0400 #ifdef RTP_DEBUG int result; /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ SetLastError (0); #endif if (_wfindnext (((WFSOBJ *)dirobj)->handle, &(((WFSOBJ *)dirobj)->fsObject)) != 0) { #ifdef RTP_DEBUG result = GetLastError(); RTP_DEBUG_OUTPUT_STR("rtp_wfile_gnext: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } return (0); #endif return (-1); }
/*----------------------------------------------------------------------* _rtp_sig_semaphore_alloc *----------------------------------------------------------------------*/ int _rtp_sig_semaphore_alloc (RTP_HANDLE *newSem, const char *name) { #ifdef LINUXTOBEIMPLEMENTED HANDLE winSemaphore; #ifdef RTP_DEBUG int result; /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ SetLastError (0); #endif if (!(winSemaphore = CreateSemaphore (NULL, 0, 10000, NULL))) { #ifdef RTP_DEBUG result = GetLastError(); RTP_DEBUG_OUTPUT_STR("rtp_sig_semaphore_alloc: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return(-1); } *newSem = (RTP_HANDLE)winSemaphore; return(0); #else return(0); #endif }
/*----------------------------------------------------------------------* rtp_net_getntoread *----------------------------------------------------------------------*/ int rtp_net_getntoread (RTP_HANDLE sockHandle, unsigned long * nToRead) { #ifdef LINUXTOBEIMPLEMENTED u_long arg; #ifdef RTP_DEBUG int result; /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ WSASetLastError (0); #endif if (ioctlsocket((SOCKET) sockHandle, FIONREAD, (u_long *) &arg) == SOCKET_ERROR) { #ifdef RTP_DEBUG result = WSAGetLastError(); RTP_DEBUG_OUTPUT_STR("rtp_net_getntoread: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } *nToRead = arg; return (0); #else return (0); #endif }
/*----------------------------------------------------------------------* rtp_file_delete *----------------------------------------------------------------------*/ int rtp_file_delete (const char * name) { #ifdef RTP_DEBUG /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ errno = 0; #endif if (unlink ((const char *)name) != 0) { #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_file_delete: error returned "); RTP_DEBUG_OUTPUT_INT(errno); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_file_delete: "); RTP_DEBUG_OUTPUT_STR("...success"); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (0); }
/*----------------------------------------------------------------------* rtp_wfile_pwd *----------------------------------------------------------------------*/ int rtp_wfile_pwd (unsigned short * name, long size) { #if (_WIN32_WINNT) >= 0x0400 #ifdef RTP_DEBUG int result; /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ SetLastError (0); #endif if (_wgetcwd (name, (int)size) == NULL) { #ifdef RTP_DEBUG result = GetLastError(); RTP_DEBUG_OUTPUT_STR("rtp_wfile_pwd: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } name = _rtp_unicode_winname_to_name (name); return (0); #endif return (-1); }
/*----------------------------------------------------------------------* rtp_net_socket_stream *----------------------------------------------------------------------*/ int rtp_net_socket_stream (RTP_HANDLE *sockHandle) { int sock; #ifdef RTP_DEBUG /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ errno = 0; #endif sock = socket(PF_INET, SOCK_STREAM, 0); if (sock == -1) { *sockHandle = ((RTP_HANDLE)-1); #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_net_socket_stream: error returned "); RTP_DEBUG_OUTPUT_INT(errno); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } *sockHandle = (RTP_HANDLE) sock; rtpnetOpenSockets++; return (0); }
/*----------------------------------------------------------------------* rtp_net_setnagle *----------------------------------------------------------------------*/ int rtp_net_setnagle (RTP_HANDLE sockHandle, unsigned int onBool) { #ifdef LINUXTOBEIMPLEMENTED int option; #ifdef RTP_DEBUG int result; /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ WSASetLastError (0); #endif option = (int)(!onBool); if ( setsockopt((SOCKET) sockHandle, IPPROTO_TCP, TCP_NODELAY, (char *) &option, sizeof (int)) == SOCKET_ERROR ) { #ifdef RTP_DEBUG result = WSAGetLastError(); RTP_DEBUG_OUTPUT_STR("rtp_net_setnagle: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } return (0); #else return (0); #endif }
/*----------------------------------------------------------------------* rtp_net_gethostbyname *----------------------------------------------------------------------*/ int rtp_net_gethostbyname (unsigned char *ipAddr, int *type, char *name) { struct hostent* hp = NULL; #ifdef RTP_DEBUG /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ h_errno = 0; #endif if (!(hp = gethostbyname((const char *)name))) { #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_net_gethostbyname: error returned "); RTP_DEBUG_OUTPUT_INT(h_errno); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } if (hp->h_addrtype != AF_INET) { return (-1); } *type = RTP_NET_TYPE_IPV4; ipAddr[0] = (unsigned char) hp->h_addr_list[0][0]; ipAddr[1] = (unsigned char) hp->h_addr_list[0][1]; ipAddr[2] = (unsigned char) hp->h_addr_list[0][2]; ipAddr[3] = (unsigned char) hp->h_addr_list[0][3]; return (0); }
/*----------------------------------------------------------------------* rtp_net_setblocking *----------------------------------------------------------------------*/ int rtp_net_setblocking (RTP_HANDLE sockHandle, unsigned int onBool) { #ifdef LINUXTOBEIMPLEMENTED u_long arg; #ifdef RTP_DEBUG int result; /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ WSASetLastError (0); #endif arg = (u_long)(!onBool); if (ioctlsocket((SOCKET) sockHandle, FIONBIO, (u_long *) &arg) == SOCKET_ERROR) { #ifdef RTP_DEBUG result = WSAGetLastError(); RTP_DEBUG_OUTPUT_STR("rtp_net_setblocking: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } return (0); #else return (0); #endif }
/*----------------------------------------------------------------------* rtp_file_gfirst *----------------------------------------------------------------------*/ int rtp_file_gfirst (void ** dirobj, char * name) { FSOBJ* winDirObj; #ifdef RTP_DEBUG int result; /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ SetLastError (0); #endif winDirObj = (FSOBJ*) malloc(sizeof(FSOBJ)); memset(winDirObj, 0, sizeof(FSOBJ)); winDirObj->handle = _findfirst((const char *) name, &(winDirObj->fsObject)); if (winDirObj->handle == (long)(-1)) { free (winDirObj); #ifdef RTP_DEBUG result = GetLastError(); RTP_DEBUG_OUTPUT_STR("rtp_file_gfirst: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } *dirobj = (void*) winDirObj; return (0); }
/*----------------------------------------------------------------------* rtp_net_setkeepalive *----------------------------------------------------------------------*/ int rtp_net_setkeepalive (RTP_HANDLE sockHandle, unsigned int onBool) { #ifdef RTP_DEBUG int result; /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ set_errno (0); #endif if (setsockopt((int) sockHandle, SOL_SOCKET, SO_KEEPALIVE, (PFCCHAR)&onBool, sizeof (int)) != 0) { #ifdef RTP_DEBUG result = xn_getlasterror(); RTP_DEBUG_OUTPUT_STR("rtp_net_setkeepalive: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } return (0); }
/*----------------------------------------------------------------------* rtp_file_get_free *----------------------------------------------------------------------*/ int rtp_file_get_free (char * name, unsigned long *total, unsigned long *free, unsigned long *sectors_per_unit, unsigned short *bytes_per_sector) { struct statfs stats; #ifdef RTP_DEBUG /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ errno = 0; #endif if (statfs ((const char *) name, &stats) != 0) { #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_file_get_free: error returned "); RTP_DEBUG_OUTPUT_INT(errno); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } *total = (unsigned long) stats.f_blocks; *free = (unsigned long) stats.f_bavail; *sectors_per_unit = (unsigned long) 1; *bytes_per_sector = (unsigned short) stats.f_bsize; return (0); }
/*----------------------------------------------------------------------* rtp_file_lseek *----------------------------------------------------------------------*/ long rtp_file_lseek (RTP_HANDLE fd, long offset, int origin) { off_t result; int relative_to; #ifdef RTP_DEBUG /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ errno = 0; #endif switch (origin) { case 0: relative_to = SEEK_SET; break; case 1: relative_to = SEEK_CUR; break; case 2: relative_to = SEEK_END; break; default: #ifdef RTP_DEBUG errno = EINVAL; RTP_DEBUG_OUTPUT_STR("rtp_file_lseek: error returned "); RTP_DEBUG_OUTPUT_INT(errno); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); break; } if ((result = lseek ((int) fd, (off_t) offset, relative_to)) == (off_t)-1) { #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_file_lseek: error returned "); RTP_DEBUG_OUTPUT_INT(errno); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } return ((long) result); }
/*----------------------------------------------------------------------* rtp_file_open *----------------------------------------------------------------------*/ int rtp_file_open (RTP_HANDLE * fdPtr, const char * name, unsigned short flag, unsigned short mode) { int fileHandle; #ifdef RTP_DEBUG /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ errno = 0; #endif fileHandle = open (name, _rtp_flag_to_operation(flag), _rtp_mode_to_permission(mode)); if (fileHandle == (-1)) { /* ----------------------------------- */ /* If trying to open a directory or */ /* opening a read only file with */ /* write privilages. This can be */ /* non-fatal if doing an open to */ /* determine the existance of a */ /* directory. */ /* ----------------------------------- */ if (errno == EACCES) { #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_file_open: non-fatal error returned "); RTP_DEBUG_OUTPUT_INT(errno); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-2); } #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_file_open: error returned "); RTP_DEBUG_OUTPUT_INT(errno); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } /* Ignore RTP_FILE_S_HIDDEN, RTP_FILE_S_SYSTEM, and RTP_FILE_S_ARCHIVE. */ *fdPtr = (RTP_HANDLE) fileHandle; return (0); }
/*----------------------------------------------------------------------* rtp_net_read_select *----------------------------------------------------------------------*/ int rtp_net_read_select (RTP_HANDLE sockHandle, long msecTimeout) { struct timeval selectTime; fd_set read_set; int result; /* ----------------------------------- */ /* read list */ /* ----------------------------------- */ FD_ZERO(&read_set); FD_SET(sockHandle, &read_set); #ifdef RTP_DEBUG /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ set_errno (0); #endif if (msecTimeout >= 0) { selectTime.tv_sec = msecTimeout / 1000; selectTime.tv_usec = (msecTimeout % 1000) * 1000; result = select(1, (PFDSET) &read_set, (PFDSET) 0, (PFDSET) 0, (PCTIMEVAL) &selectTime); } else { result = select(1, (PFDSET) &read_set, (PFDSET) 0, (PFDSET) 0, (PCTIMEVAL) NULL); } /* if (result == 1) | { | if (!xn_tcp_is_read(sockHandle)) | { | result = (-1); | } | } */ /* if an error or if it timed out */ if (result <= 0) { #ifdef RTP_DEBUG result = xn_getlasterror(); RTP_DEBUG_OUTPUT_STR("rtp_net_read_select: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } return (0); }
/*----------------------------------------------------------------------* rtp_net_getsockname *----------------------------------------------------------------------*/ int rtp_net_getsockname (RTP_HANDLE sockHandle, unsigned char *ipAddr, int *port, int *type) { struct sockaddr_in localAddr; int localLen; #ifdef RTP_DEBUG int result; #endif localLen = sizeof (localAddr); memset(&localAddr, 0, localLen); #ifdef RTP_DEBUG /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ set_errno (0); #endif if (getsockname ((int) sockHandle, (PSOCKADDR) &localAddr, (PFINT) &localLen) != 0) { #ifdef RTP_DEBUG result = xn_getlasterror(); RTP_DEBUG_OUTPUT_STR("rtp_net_getsockname: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } if (ipAddr) { unsigned long d = localAddr.sin_addr.s_addr; unsigned char *ptr = (unsigned char *) &d; *type = RTP_NET_TYPE_IPV4; ipAddr[0] = ptr[0]; ipAddr[1] = ptr[1]; ipAddr[2] = ptr[2]; ipAddr[3] = ptr[3]; } if (port) { *port = ntohs (localAddr.sin_port); } return (0); }
/*----------------------------------------------------------------------* _rtp_sig_semaphore_wait_timed *----------------------------------------------------------------------*/ int _rtp_sig_semaphore_wait_timed (RTP_HANDLE semHandle, long msecs) { #ifdef LINUXTOBEIMPLEMENTED DWORD result; #ifdef RTP_DEBUG int err; /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ SetLastError (0); #endif if (msecs == (-1)) { result = WaitForSingleObject((HANDLE)semHandle, INFINITE); } else { result = WaitForSingleObject((HANDLE)semHandle, msecs); } if (result == WAIT_FAILED) { #ifdef RTP_DEBUG err = GetLastError(); RTP_DEBUG_OUTPUT_STR("rtp_sig_semaphore_wait_timed: error returned "); RTP_DEBUG_OUTPUT_INT(err); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } else if (result == WAIT_ABANDONED) { #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_sig_semaphore_wait_timed: wait abandoned.\n"); #endif return (-1); } else if (result == WAIT_TIMEOUT) { return (-1); } return (0); #else return (0); #endif }
/*----------------------------------------------------------------------* rtp_net_read_select *----------------------------------------------------------------------*/ int rtp_net_read_select (RTP_HANDLE sockHandle, long msecTimeout) { #ifdef LINUXTOBEIMPLEMENTED struct timeval selectTime; fd_set read_set; int result; /* ----------------------------------- */ /* write list */ /* ----------------------------------- */ FD_ZERO(&read_set); FD_SET((SOCKET) sockHandle, &read_set); #ifdef RTP_DEBUG /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ WSASetLastError(0); #endif if (msecTimeout >= 0) { selectTime.tv_sec = msecTimeout / 1000; selectTime.tv_usec = (msecTimeout % 1000) * 1000; result = select(1, (fd_set *) &read_set, (fd_set *) 0, (fd_set *) 0, (const struct timeval *) &selectTime); } else { result = select(1, (fd_set *) &read_set, (fd_set *) 0, (fd_set *) 0, (const struct timeval *) NULL); } /* if an error or if it timed out */ if ((result == SOCKET_ERROR) || (result == 0)) { #ifdef RTP_DEBUG result = WSAGetLastError(); RTP_DEBUG_OUTPUT_STR("rtp_net_read_select: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } return (0); #else return (0); #endif }
/*----------------------------------------------------------------------* rtp_file_gfirst *----------------------------------------------------------------------*/ int rtp_file_gfirst (void ** dirobj, char * name) { FSOBJ* linDirObj; int result; linDirObj = (FSOBJ*) malloc(sizeof(FSOBJ)); memset(linDirObj, 0, sizeof(FSOBJ)); result = glob((const char *) name, 0, NULL, &(linDirObj->globdata)); if (result != 0) { free (linDirObj); #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_file_gfirst: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } linDirObj->currentPath = 0; if (stat (linDirObj->globdata.gl_pathv[linDirObj->currentPath], &linDirObj->statdata) == -1) { globfree(&linDirObj->globdata); free (linDirObj); #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_file_gfirst: error returned "); RTP_DEBUG_OUTPUT_INT(errno); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } *dirobj = (void*) linDirObj; return (0); }
/*----------------------------------------------------------------------* rtp_net_write_select *----------------------------------------------------------------------*/ int rtp_net_write_select (RTP_HANDLE sockHandle, long msecTimeout) { #ifdef LINUXTOBEIMPLEMENTED long selectTime; fd_set write_set; int result; /* ----------------------------------- */ /* write list */ /* ----------------------------------- */ IP_FD_ZERO(&write_set); IP_FD_SET((SOCKET) sockHandle, &write_set); #ifdef RTP_DEBUG /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ WSASetLastError(0); #endif if (msecTimeout >= 0) { selectTime = msecTimeout / 1000; result = select(1, (fd_set *) 0, (fd_set *) &write_set, (fd_set *) 0, selectTime); } else { result = select(1, (fd_set *) 0, (fd_set *) &write_set, (fd_set *) 0, 0); } /* if an error or if it timed out */ if ((result == SOCKET_ERROR) || (result == 0)) { #ifdef RTP_DEBUG result = WSAGetLastError(); RTP_DEBUG_OUTPUT_STR("rtp_net_write_select: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } return (0); #else return (0); #endif }