78 lines · c
1//===-- RNBSocket.h ---------------------------------------------*- C++ -*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8//9// Created by Greg Clayton on 12/12/07.10//11//===----------------------------------------------------------------------===//12 13#ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_RNBSOCKET_H14#define LLDB_TOOLS_DEBUGSERVER_SOURCE_RNBSOCKET_H15 16#include "DNBTimer.h"17#include "RNBDefs.h"18#include <string>19#include <sys/socket.h>20#include <sys/types.h>21 22#ifdef WITH_LOCKDOWN23#include "lockdown.h"24#endif25 26class RNBSocket {27public:28 typedef void (*PortBoundCallback)(const void *baton, uint16_t port);29 30 RNBSocket()31 : m_fd(-1),32#ifdef WITH_LOCKDOWN33 m_fd_from_lockdown(false), m_ld_conn(),34#endif35 m_timer(true) // Make a thread safe timer36 {37 }38 ~RNBSocket(void) { Disconnect(false); }39 40 rnb_err_t Listen(const char *listen_host, uint16_t port,41 PortBoundCallback callback, const void *callback_baton);42 rnb_err_t Connect(const char *host, uint16_t port);43 44 rnb_err_t useFD(int fd);45 46#ifdef WITH_LOCKDOWN47 rnb_err_t ConnectToService();48#endif49 rnb_err_t OpenFile(const char *path);50 rnb_err_t Disconnect(bool save_errno);51 rnb_err_t Read(std::string &p);52 rnb_err_t Write(const void *buffer, size_t length);53 54 bool IsConnected() const { return m_fd != -1; }55 void SaveErrno(int curr_errno);56 DNBTimer &Timer() { return m_timer; }57 58 static int SetSocketOption(int fd, int level, int option_name,59 int option_value);60 61private:62 RNBSocket(const RNBSocket &) = delete;63 64protected:65 rnb_err_t ClosePort(int &fd, bool save_errno);66 67 int m_fd; // Socket we use to communicate once conn established68 69#ifdef WITH_LOCKDOWN70 bool m_fd_from_lockdown;71 lockdown_connection m_ld_conn;72#endif73 74 DNBTimer m_timer;75};76 77#endif // LLDB_TOOLS_DEBUGSERVER_SOURCE_RNBSOCKET_H78