mirror of
https://github.com/Mahdi-zarei/nekoray.git
synced 2025-12-18 20:50:09 +08:00
* refactor: migrate from grpc to protorpc * fix * fix * fix * cleanup * Update mainwindow_grpc.cpp * Update RPC.cpp * fix --------- Co-authored-by: parhelia512 <0011d3@gmail.com>
50 lines
925 B
C++
50 lines
925 B
C++
// Copyright 2013 <chaishushan{AT}gmail.com>. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
#pragma once
|
|
|
|
#ifndef PROTORPC_CONN_H__
|
|
#define PROTORPC_CONN_H__
|
|
|
|
#include <stdarg.h>
|
|
#include <stdint.h>
|
|
#include <string>
|
|
|
|
namespace protorpc {
|
|
|
|
// Initialize socket services
|
|
bool InitSocket();
|
|
|
|
// Stream-oriented network connection.
|
|
class Conn {
|
|
public:
|
|
Conn(int fd=0): sock_(fd) { InitSocket(); }
|
|
~Conn() {}
|
|
|
|
bool IsValid() const;
|
|
bool DialTCP(const char* host, int port);
|
|
bool ListenTCP(int port, int backlog=5);
|
|
void Close();
|
|
|
|
Conn* Accept();
|
|
|
|
bool Read(void* buf, int len);
|
|
bool Write(void* buf, int len);
|
|
|
|
bool ReadUvarint(uint64_t* x);
|
|
bool WriteUvarint(uint64_t x);
|
|
|
|
bool RecvFrame(::std::string* data);
|
|
bool SendFrame(const ::std::string* data);
|
|
|
|
private:
|
|
|
|
int sock_;
|
|
};
|
|
|
|
} // namespace protorpc
|
|
|
|
#endif // PROTORPC_CONN_H__
|
|
|