socket.h

来自「通用网络游戏开发框架」· C头文件 代码 · 共 52 行

H
52
字号
// This file needs -*- c++ -*- mode
// ============================================================================
// Socket public interface
//
// (c) 2003 Ken Reed
//
// This is free software. You can redistribute it and/or modify it under the
// terms of the GNU General Public License version 2 as published by the Free
// Software Foundation.
// ============================================================================

#pragma once

#include <iostream>
#include <string>

#include "exception.h"

class Buffer;

class Sock_exception : public Exception
{
public:
   Sock_exception(const std::string & message);
};

class Socket : public std::iostream {
public:
    Socket(int port = -1);
   ~Socket();

   int    bytes_read     (bool reset_count = false);
   int    bytes_sent     (bool reset_count = false);
   int    get_number     ();
   void   close          ();
   void   connect        (const char * const host, const int port);
   void   getline        (std::string & s);
   void   listen         ();
   void   read_binary    (void * buffer, int buffer_size);
   void   write_binary   (void * buffer, int buffer_size);
   void   set_connection (void * handle);
   void   set_trace      (const char * filename);
   void * get_connection ();

protected:
   Buffer * rdbuf();

private:
   Socket (const Socket & Socket);         // No copying allowed
   void   bind           (const int port);
};

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?