Source: ../../libxipc/xrl_pf_stcp.hh
|
|
|
|
// -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
// Copyright (c) 2001-2003 International Computer Science Institute
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software")
// to deal in the Software without restriction, subject to the conditions
// listed in the XORP LICENSE file. These conditions include: you must
// preserve this copyright notice, and you cannot mention the copyright
// holders in advertising related to the Software without their permission.
// The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This
// notice is a summary of the XORP LICENSE file; the license in that file is
// legally binding.
// $XORP: xorp/libxipc/xrl_pf_stcp.hh,v 1.9 2003/05/09 21:00:53 hodson Exp $
#ifndef __LIBXIPC_XRL_PF_STCP_HH__
#define __LIBXIPC_XRL_PF_STCP_HH__
#include "xrl_pf.hh"
#include "libxorp/asyncio.hh"
// ----------------------------------------------------------------------------
// XRL Protocol Family : Simplest TCP
class STCPRequestHandler;
class XrlPFSTCPSender;
class STCPPacketHeader;
struct RequestState {
XrlPFSTCPSender* parent;
uint32_t seqno;
Xrl xrl;
XorpTimer timeout;
XrlPFSender::SendCallback callback;
RequestState(XrlPFSTCPSender* p, uint32_t sno, const Xrl& x,
const XrlPFSender::SendCallback& cb)
: parent(p), seqno(sno), xrl(x), callback(cb)
{}
bool has_seqno(uint32_t n) const { return seqno == n; }
};
class XrlPFSTCPListener : public XrlPFListener {
public:
XrlPFSTCPListener(EventLoop& e, XrlDispatcher* xr = 0, uint16_t port = 0)
throw (XrlPFConstructorError);
~XrlPFSTCPListener();
const char* address() const { return _address_slash_port.c_str(); }
const char* protocol() const { return _protocol; }
void add_request_handler(STCPRequestHandler* h);
void remove_request_handler(const STCPRequestHandler* h);
private:
void connect_hook(int fd, SelectorMask m);
int _fd;
string _address_slash_port;
list<STCPRequestHandler*> _request_handlers;
static const char* _protocol;
static const uint32_t _timeout_period;
};
class XrlPFSTCPSender : public XrlPFSender {
public:
XrlPFSTCPSender(EventLoop& e, const char* address = NULL)
throw (XrlPFConstructorError);
virtual ~XrlPFSTCPSender();
void send(const Xrl& x, const XrlPFSender::SendCallback& cb);
bool sends_pending() const { return true; }
bool alive() const { return _fd > 0; }
static const char* protocol() { return _protocol; }
// Response timeout control
void set_timeout_ms(uint32_t t) { _timeout_ms = t; }
uint32_t timeout_ms() const { return _timeout_ms; }
// Keepalive interval
void set_keepalive_ms(uint32_t t);
uint32_t keepalive_ms() const { return _keepalive_ms; }
private:
void send_first_request();
void die(const char* reason);
void prepare_packet(const XrlPFSender::Request& r);
int _fd;
// Transmission related
AsyncFileWriter* _writer;
list<RequestState> _requests_pending; // All requests pending
list<RequestState> _requests_sent; // All requests sent
vector<uint8_t> _request_packet;
uint32_t _current_seqno;
void update_writer(AsyncFileWriter::Event e,
const uint8_t* buffer,
size_t buffer_bytes,
size_t bytes_done);
RequestState* find_request(uint32_t seqno);
void postpone_timeout(uint32_t seqno);
void timeout_request(uint32_t seqno);
// Tunable timer variables
uint32_t _timeout_ms;
uint32_t _keepalive_ms;
// Reception related
AsyncFileReader* _reader;
vector<uint8_t> _reply;
const STCPPacketHeader* _sph;
void prepare_for_reply_header();
void recv_data(AsyncFileReader::Event ev,
const uint8_t* buffer,
size_t buffer_bytes,
size_t offset);
void dispatch_reply();
// Keepalive related
XorpTimer _keepalive_timer;
vector<uint8_t> _keepalive_packet;
bool _keepalive_in_progress;
inline void start_keepalives();
inline void stop_keepalives();
inline void postpone_keepalive();
inline bool send_keepalive();
void confirm_keepalive(AsyncFileOperator::Event e,
const uint8_t* buffer,
size_t buffer_bytes,
size_t offset);
// General stuff
static const char* _protocol;
};
#endif // __LIBXIPC_XRL_PF_STCP_HH__
Generated by: pavlin on possum.icir.org on Mon Jun 9 13:23:50 2003, using kdoc 2.0a54+XORP. |