macedon_connection.cc
来自「这是一个著名的应用层组播中间件的源码」· CC 代码 · 共 185 行
CC
185 行
//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.#include <unistd.h>#include <stdio.h>#include "macedon.h"#include "macedon_connection.h"macedon_transport_work::macedon_transport_work() : stuff(0), tot_size(0), running_buffer(0), running_size(0), neighbor(NULL){}macedon_transport_work::~macedon_transport_work(){ if (stuff == (unsigned char *)0xeeeeeeee) { printf("Something hosed with stuff\n"); exit(97); } if (stuff) { ::free (stuff); stuff = 0; }}macedon_transport_send_work::macedon_transport_send_work() : next(NULL){}macedon_transport_send_work::~macedon_transport_send_work(){}macedon_transport_recv_work::macedon_transport_recv_work() : header_size(0), data_size(0), field_bytes(0){}macedon_transport_recv_work::~macedon_transport_recv_work(){ // printf ("recv work freeing %x in destruct\n", this); // fflush(stdout);}macedon_connection::macedon_connection(int destination, int in_index, int port, macedon_transport *intrans) : status(MACEDON_CONNECTION_STATUS_disconnected), descriptor(-1), time_last_used(wall_clock()), items_sent(0), items_received(0), items_rejected(0), items_queued(0), bytes_sent(0), bytes_received(0), recv_in_progress(NULL), time_connect_initiated (0.0), virtual_time_initiated(0), send_queue(NULL), send_queue_last(NULL), send_queue_items(0), next(NULL), trans(intrans), index(in_index){ bzero(&neigh_socket_address, sizeof(neigh_socket_address)); neigh_socket_address.sin_family = AF_INET; neigh_socket_address.sin_port = port; neigh_socket_address.sin_addr.s_addr = destination;}macedon_connection::~macedon_connection(){ close_descriptor (); status = MACEDON_CONNECTION_STATUS_disconnected; while (send_queue) { macedon_transport_work* unit = pop_front(); delete unit; } if (recv_in_progress) delete recv_in_progress; recv_in_progress = 0;}// ---------------------------------------------- // close_descriptor// ---------------------------------------------- int macedon_connection::close_descriptor (){ if (descriptor != - 1) { ::shutdown( descriptor, SHUT_RDWR); ::close( descriptor); descriptor = - 1; }}void macedon_connection::queue_back(macedon_transport_send_work *in) { if (send_queue) { send_queue_last->next = in; } else { send_queue = in; } macedon_transport_send_work *temp = in; send_queue_items++; while (temp->next) { send_queue_items++; temp = temp->next; } send_queue_last = temp;}void macedon_connection::queue_front(macedon_transport_send_work *in){ macedon_transport_send_work *temp = in; send_queue_items++; while (temp->next) { send_queue_items++; temp = temp->next; } temp->next = send_queue; send_queue = in;}macedon_transport_send_work *macedon_connection::pop_front() { macedon_transport_send_work *temp = NULL; if (send_queue) { temp = send_queue; send_queue = send_queue->next; send_queue_items--; } return temp;}void macedon_connection::set_filter(#ifdef NEW_BW_FILTERconst bandwidth_time_filter& filter#elseconst bandwidth_filter& filter#endif) { bandwidth = filter;}#ifdef NEW_BW_FILTERbandwidth_time_filter&#elsebandwidth_filter&#endifmacedon_connection::get_filter() { return bandwidth;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?