#ifndef n_TcpConnection_H
#define n_TcpConnection_H

/*
 *
 * nucleo/network/tcp/TcpConnection.H --
 *
 * Copyright (C) Nicolas Roussel
 *
 * See the file LICENSE for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 */

#include <nucleo/core/ReactiveObject.H>
#include <nucleo/core/FileKeeper.H>

#include <string>

namespace nucleo {

  class TcpConnection : public ReactiveObject {

  private:
    
    int _socket ;
    bool _closeSocketOnDestroy ;

    FileKeeper *_tcpw ;

  protected:

    void react(Observable*) ;

  public:

    TcpConnection(int socket, bool close=false) ;
    TcpConnection(const char *hostname, int port, bool close=false) ; 

    int getFd(void) { return _socket ; }

    unsigned int send(const char *data, unsigned int length, bool complete=true) ;
    unsigned int receive(char *data, unsigned int length, bool complete) ;

    std::string machineLookUp(void) ;
    std::string userLookUp(int millisecs=500) ;

    ~TcpConnection(void) ;

  } ;

}

#endif
