src/Network/Node.cc
author Tero Marttila <terom@fixme.fi>
Tue, 27 Jan 2009 03:02:02 +0200
changeset 441 f769fab21a6c
parent 431 c6d7272a164b
permissions -rw-r--r--
fix bug with NetworkBufferOutput where push_write doesn't update offset
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     1
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     2
#include <cassert>
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     3
186
0738f2949a2b move src/Network% to src/Network/%
terom
parents: 185
diff changeset
     4
#include "Node.hh"
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     5
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     6
NetworkNode::NetworkNode (NetworkSession &session, NetworkTCPTransport *tcp, NetworkUDP *udp, const NetworkAddress &address) :
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     7
    session(session), tcp(tcp), udp(udp), address(address) {
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     8
    
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     9
    // connect signals
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    10
    slots.connect(tcp->sig_disconnect(), this, &NetworkNode::on_disconnect);
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    11
    slots.connect(tcp->sig_packet(), &session, &NetworkSession::handle_message, this);
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    12
    
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    13
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    14
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    15
NetworkNode::~NetworkNode (void) {
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    16
    delete tcp;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    17
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    18
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    19
void NetworkNode::on_disconnect (void) {
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    20
    // tell session
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    21
    session.handle_disconnect(this);
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    22
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    23
    // fire signal
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    24
    _sig_disconnected();
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    25
    
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    26
    // delete
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    27
//    delete this;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    28
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    29
431
c6d7272a164b rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
Tero Marttila <terom@fixme.fi>
parents: 202
diff changeset
    30
void NetworkNode::send_pkt (const NetworkPacketBuffer &pkt, bool reliable) {
202
b3f5d766391e support sending of raw packets
terom
parents: 200
diff changeset
    31
    // either tcp or udp
b3f5d766391e support sending of raw packets
terom
parents: 200
diff changeset
    32
    if (reliable) {
b3f5d766391e support sending of raw packets
terom
parents: 200
diff changeset
    33
        assert(tcp);
b3f5d766391e support sending of raw packets
terom
parents: 200
diff changeset
    34
b3f5d766391e support sending of raw packets
terom
parents: 200
diff changeset
    35
        tcp->write_packet(pkt);
b3f5d766391e support sending of raw packets
terom
parents: 200
diff changeset
    36
b3f5d766391e support sending of raw packets
terom
parents: 200
diff changeset
    37
    } else {
b3f5d766391e support sending of raw packets
terom
parents: 200
diff changeset
    38
        udp->sendto(pkt, address);
b3f5d766391e support sending of raw packets
terom
parents: 200
diff changeset
    39
    }
b3f5d766391e support sending of raw packets
terom
parents: 200
diff changeset
    40
b3f5d766391e support sending of raw packets
terom
parents: 200
diff changeset
    41
}
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    42
        
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    43
const NetworkAddress& NetworkNode::getRemoteAddress (void) {
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    44
    return address;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    45
}