RNBSocket.h revision ff39f746ebaa3710c44ba49bd9b0a6cf05f60a3f
1//===-- RNBSocket.h ---------------------------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// Created by Greg Clayton on 12/12/07. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef __RNBSocket_h__ 15#define __RNBSocket_h__ 16 17#include "RNBDefs.h" 18#include <sys/socket.h> 19#include <sys/types.h> 20#include <string> 21#include "DNBTimer.h" 22 23class RNBSocket 24{ 25public: 26 27 RNBSocket () : 28 m_conn_port (-1), 29 m_conn_port_from_lockdown (false), 30 m_timer (true) // Make a thread safe timer 31 { 32 } 33 ~RNBSocket (void) 34 { 35 Disconnect (false); 36 } 37 38 rnb_err_t Listen (in_port_t listen_port_num); 39 rnb_err_t Connect (const char *host, uint16_t port); 40 41#if defined (__arm__) 42 rnb_err_t ConnectToService(); 43#endif 44 rnb_err_t OpenFile (const char *path); 45 rnb_err_t Disconnect (bool save_errno); 46 rnb_err_t Read (std::string &p); 47 rnb_err_t Write (const void *buffer, size_t length); 48 49 bool IsConnected () const { return m_conn_port != -1; } 50 void SaveErrno (int curr_errno); 51 DNBTimer& Timer() { return m_timer; } 52 53 static int SetSocketOption(int fd, int level, int option_name, int option_value); 54private: 55 // Outlaw some constructors 56 RNBSocket (const RNBSocket &); 57 58protected: 59 rnb_err_t ClosePort (int& fd, bool save_errno); 60 61 int m_conn_port; // Socket we use to communicate once conn established 62 bool m_conn_port_from_lockdown; 63 DNBTimer m_timer; 64}; 65 66 67#endif // #ifndef __RNBSocket_h__ 68