Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

RMI for C++

, 6 Aug 2009
User-friendly remote method invocation in C++.
rcf.zip
RCF
demo
vs2003
RCF
Client
Server
doc
include
RCF
Connection.inl
Marshal.inl
Multiplexer.inl
RCF.inl
RcfServer.inl
ServerStub.inl
Protocol
util
Platform
Compiler
bcc55
cw80
gcc32
icl70
msvc71
Library
bcc55
cw80
gcc32
msvc60
msvc71
Machine
SPARC
x86
OS
Cygwin
Unix
Windows
System
NonWindows
Windows
Threads
SF
src
RCF
Protocol
util
SF
test
Jamfile
Jamrules
borland
Jamfile
Jamrules
vs2003
RCF
RCF
RCFTest
// OS-specific details - Unix common

#ifndef _UTIL_PLATFORM_OS_UNIX_COMMON_HPP_
#define _UTIL_PLATFORM_OS_UNIX_COMMON_HPP_

#if defined(sun) || defined(__sun) || defined(__sun__)
#define BSD_COMP                // Needs to be defined in order to use FIONBIO in ioctl()
#define MSG_NOSIGNAL 0            // MSG_NOSIGNAL flag for send() not implemented on Solaris
#endif

#include <iostream>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/uio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>

#include <cerrno>

#ifndef __UNIX__
#define __UNIX__
#endif

// O_BINARY is not defined in Unix (all files are "binary" anyway)
#ifndef O_BINARY
#define O_BINARY 0
#endif

#ifndef SOCKET
#define SOCKET int
#endif

#ifndef INVALID_SOCKET
#define INVALID_SOCKET -1
#endif

// Solaris doesn't define INADDR_NONE, for some reason
#ifndef INADDR_NONE
#define INADDR_NONE ((unsigned long) -1)
#endif

namespace Platform {

    namespace OS {

        inline void OutputDebugString(const char *sz) 
        { 

#ifdef OUTPUTDEBUGSTRING_TO_STDERR
            fprintf(stderr, "%s", sz);
#endif

#ifdef OUTPUTDEBUGSTRING_TO_STDOUT
            fprintf(stdout, "%s", sz);
#endif

#ifdef OUTPUTDEBUGSTRING_TO_FILE
            static FILE *file = fopen( "OutputDebugString.txt", "w" );
            fprintf(file, "%s", sz);
#endif

        }

        inline int GetCurrentThreadId() { return 0; } //TODO (pthread_self() ?)

        inline std::string GetErrorString(int err) { return std::string( strerror(err) ); }
        inline std::string GetErrorString() { return GetErrorString( errno ); }
        
        inline void Sleep(unsigned int seconds) { ::sleep(seconds); }
        
        namespace Socket {
            
            inline int recv(int fd, char *buf, int len, int flags)              
            { 
                return ::recv(fd, buf, len, flags); 
            }

            inline int send(int fd, const char *buf, int len, int flags)        
            { 
                return ::send(fd, buf, len, flags | MSG_NOSIGNAL); 
            }

            inline int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timeval *timeout) 
            { 
                return ::select( nfds, readfds, writefds, exceptfds, const_cast<struct timeval *>(timeout) ); 
            }

            inline int accept(int fd, sockaddr *addr, int *addrlen)
            { 
                socklen_t addrlen_ = *addrlen; 
                int ret = ::accept(fd, addr, &addrlen_); 
                *addrlen = addrlen_; 
                return ret; 
            }

            inline int connect(int fd, const sockaddr *name, int namelen)
            {
                return ::connect(fd, name, namelen); 
            }

            inline int closesocket(int fd)                                      
            { 
                return ::close(fd); 
            }

            inline void setblocking(SOCKET fd, bool bBlocking)                  
            { 
                int arg = bBlocking ? 0 : 1; 
                ::ioctl(fd, FIONBIO, &arg); 
            }

            inline int GetLastError()                                           
            { 
                return errno; 
            }

            static const int ERR_EWOULDBLOCK = EWOULDBLOCK;
            static const int ERR_EINPROGRESS = EINPROGRESS;
            static const int ERR_ECONNRESET = ECONNRESET;
            static const int ERR_ECONNABORTED = ECONNABORTED;
            static const int ERR_ECONNREFUSED = ECONNREFUSED;

        } //namespace Socket

    } // namespace OS;

} // namespace Platform


#endif //! _UTIL_PLATFORM_OS_UNIX_COMMON_HPP_

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Jarl Lindrud

Australia Australia
Software developer, ex-resident of Sweden and now living in Canberra, Australia, working on distributed C++ applications. Jarl enjoys programming, but prefers skiing and playing table tennis. He derives immense satisfaction from referring to himself in third person.

| Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 6 Aug 2009
Article Copyright 2005 by Jarl Lindrud
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid