Click here to Skip to main content
11,576,692 members (59,218 online)
Click here to Skip to main content
Add your own
alternative version

RMI for C++

, 6 Aug 2009 CPOL 525K 3.9K 147
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 - Windows

#ifndef _UTIL_PLATFORM_OS_WINDOWS_OS_HPP_
#define _UTIL_PLATFORM_OS_WINDOWS_OS_HPP_

// With Codewarrior we get multiple redefinition problems when including <winsock2.h> and <windows.h>.
// Easiest way aound seems to be a project-wide definition of WIN32_LEAN_AND_MEAN.

#ifdef WIN32_LEAN_AND_MEAN
#include <winsock2.h>
#include <windows.h>
#else
//#define WIN32_LEAN_AND_MEAN
//#include <winsock2.h>
#include <windows.h>
//#undef WIN32_LEAN_AND_MEAN
#endif

#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <assert.h>

#ifndef __WINDOWS__
#define __WINDOWS__
#endif

#if !defined(NDEBUG) && !defined(_DEBUG)
#define _DEBUG
#endif

namespace Platform {

    namespace OS {

        inline void OutputDebugString(const char *sz) 
        { 
            ::OutputDebugString(sz); 

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

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

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

        }

        inline std::string GetErrorString(int err)
        {
            std::string errorString = "Error string lookup failed";
            LPVOID lpMsgBuf;
            if (FormatMessage(
                FORMAT_MESSAGE_ALLOCATE_BUFFER |
                FORMAT_MESSAGE_FROM_SYSTEM |
                FORMAT_MESSAGE_IGNORE_INSERTS,
                NULL,
                err/*GetLastError()*/,
                MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
                (char *) &lpMsgBuf,
                0,
                NULL ))
            {
                errorString = (const char *) lpMsgBuf;
                LocalFree( lpMsgBuf );
            }

            return errorString;
        }

        inline std::string GetErrorString() { return GetErrorString( ::GetLastError() ); }

        inline int GetCurrentThreadId() { return ::GetCurrentThreadId(); }

        inline void Sleep(unsigned int seconds) { return ::Sleep(1000*seconds); }
        
        namespace Socket {

            typedef ::SOCKET 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); 
            }

            inline int accept(int fd, sockaddr *addr, int *addrlen)
            { 
                return (int) ::accept(fd, addr, addrlen); 
            }

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

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

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

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

            inline int GetLastError()                                               
            { 
                return ::WSAGetLastError(); 
            }

            static const int ERR_EWOULDBLOCK = WSAEWOULDBLOCK;
            static const int ERR_EINPROGRESS = WSAEINPROGRESS;
            static const int ERR_ECONNRESET = WSAECONNRESET;
            static const int ERR_ECONNABORTED = WSAECONNABORTED;
            static const int ERR_ECONNREFUSED = WSAECONNREFUSED;

            
        } //namespace Socket

    } // namespace OS;

} // namespace Platform

#endif //! _UTIL_PLATFORM_OS_WINDOWS_OS_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.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150603.1 | Last Updated 6 Aug 2009
Article Copyright 2005 by Jarl Lindrud
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid