⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 macedon_transport.h

📁 这是一个著名的应用层组播中间件的源码
💻 H
字号:
//Copyright (c) 2004, Charles Killian, Adolfo Rodriguez, Dejan Kostic, Sooraj Bhat, and Amin Vahdat//All rights reserved.////Redistribution and use in source and binary forms, with or without//modification, are permitted provided that the following conditions are met:////   * Redistributions of source code must retain the above copyright//     notice, this list of conditions and the following disclaimer.//   * Redistributions in binary form must reproduce the above copyright//     notice, this list of conditions and the following disclaimer in//     the documentation and/or other materials provided with the//     distribution.//   * Neither the names of Duke University nor The University of//     California, San Diego, nor the names of its contributors//     may be used to endorse or promote products derived from//     this software without specific prior written permission.////THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"//AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE//IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE//FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL//DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,//OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE//USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#ifndef __macedon_transport#define __macedon_transport#include "macedon_connection.h"#include "macedon.h"// #define TRANSPORT_TRACE #define TRANSPORT_TRACE_CONNECT 1// #define TRANSPORT_MASSIVE_TRACE #define MAX_FDS 1010class  macedon_transport_receiver{};void *worker_wrapper (void *); typedef  void ( macedon_transport_receiver::*macedon_recv_handler)  ( int,     unsigned char *, int,     unsigned char *, int);typedef  void  ( macedon_transport_receiver::*tr_handler)      ( int,        unsigned char *, int,        unsigned char *, int);typedef  void  ( macedon_transport_receiver::*er_handler)      ( int,         void*        );class macedon_transport {public:  macedon_transport (int ipaddr, int port, 		     int queue_size );  virtual ~macedon_transport ( );  // API functions go here  int register_receiver (macedon_transport_receiver* receiver, 			 tr_handler handler, er_handler er_handler_p);  int send (int destination, 	    unsigned char *header_data, 	    int header_size,	    unsigned char *data, 	    int size);  int send (int destination,       int index,	    unsigned char *header_data, 	    int header_size,	    unsigned char *data, 	    int size);  int abort_destination (int destination);  int close (int destination);  int close (int destination, int index);  void create_connection_if_needed (int destination, int index);  int have_room (int destination, int index);  int queued (int destination, int index);protected:  int lock ();   int try_lock ();   void unlock ();  macedon_connection* find_macedon_connection (int destination, int index);  macedon_connection* find_macedon_connection_by_fd (int destination);  macedon_connection* find_macedon_connection_by_time (double mytime);  macedon_connection* find_macedon_connection_by_vtime (int mytime);  int find_available_index(int destination);  macedon_connection* new_macedon_connection (int destination, int useport, int index);  macedon_connection* new_macedon_connection_available_index (int destination, int useport, int* index);public:  void *worker ();  virtual int send_more (macedon_connection *) = 0;  pthread_t thread_id;  double get_bandwidth (int destination, int& valid);#ifdef NEW_BW_FILTER  void start_bw_segment(int destination);  void finish_bw_segment(int destination);#endifprotected:  // expected from the upper class  virtual void wait_for_work () = 0;  virtual void do_work () = 0;  virtual int recv_more (macedon_connection *) = 0;  virtual void terminate (int code = 0) = 0;  virtual int transport_connect(macedon_connection *) = 0;  virtual int transport_disconnect(macedon_connection *) = 0;  virtual int transport_abort (macedon_connection *); //default method is empty  // general stuff  int initialized;  pthread_mutex_t pool_lock;   int lock_held; //the thread id of the holding thread  int from_agent; //set to 1 when the calling thread is a thread from the agent.  (i.e. TCP defers sends)  int here_addr_;       //bind address  int port;        // sockets port  int queue_size;   // 0 means unlimited queued pkts  // receiver knowledge - make compatible with transport for now  macedon_transport_receiver* receiver;  tr_handler receive_handler;  er_handler error_handler;  // connection stuff  macedon_connection *macedon_connections;   //  list < macedon_connection*> macedon_connections;   //  hash_map < int, macedon_connection*, hash < int >, equal_integer> hash_macedon_connections;};#endif //__macedon_transport

⌨️ 快捷键说明

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