/** \file
 *
 *  Contains the SocketClient class declaration.
 *
 *  Copyright (c) 2007,2008,2009 MBARI
 *  MBARI Proprietary Information.  All Rights Reserved
 */

#ifndef SOCKETCLIENT_H_
#define SOCKETCLIENT_H_

#include "Socket.h"

/**
 *  Implements a Socket client for communicating with SocketServer
 *  instances.
 *
 *  \ingroup modules_simulator
 */
class SocketClient : public Socket
{
public:

    SocketClient( const char* host, int port )
#ifndef __GAZEBO
    throw( SocketException )
#endif
    ;

    /**
     * Connection with timeout.
     *
     * According to `man connect`, the implementation is based on the following sequence of system
     * calls as needed:
     *  - fcntl  (to put socket in non-blocking mode)
     *  - connect
     *  - select  (called if connect fails with EINPROGRESS)
     *  - getsockopt  (called to verify that socket is OK when select indicates socket is "ready")
     *
     * The timeout parameter is used in the select system call.
     *
     * \param host
     * \param port
     * \param timeoutMillis
     *      Timeout in millis. A value of 100 or more has worked well according to testing
     *      with client on testhyssim and server on bufflehead.
     *
     * \throws SocketException
     *      If some error occurs.
     *      In particular, the thrown exception will have getErrno() == EAGAIN if one of
     *      the following occurs:
     *          - connection refused (No-one listening on the remote address)
     *          - timeout while trying to connect
     */
    SocketClient( const char* host, int port, int timeoutMillis )
#ifndef __GAZEBO
    throw( SocketException )
#endif
    ;

    virtual ~SocketClient()
    {}
};


#endif /*SOCKETCLIENT_H_*/
