Skip to content

Commit

Permalink
fixed the issue #3
Browse files Browse the repository at this point in the history
  • Loading branch information
ytakano committed Jul 11, 2011
1 parent dff18f1 commit 90d4d63
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion example/example3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// include libcage's header
#include <libcage/cage.hpp>

const int max_node = 5;
const int max_node = 100;
const int port = 10000;
libcage::cage *cage;
event *ev;
Expand Down
13 changes: 12 additions & 1 deletion src/cage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ namespace libcage {
void join(std::string host, int port,
callback_join func);

// for rdp
// for reliable datagram transmission like TCP
//
// NOTICE:
// Currentry, this protocol doesn't support congestion
// control.
int rdp_listen(uint16_t sport,
callback_rdp_event func);
int rdp_connect(uint16_t sport, id_ptr did,
Expand All @@ -84,6 +88,13 @@ namespace libcage {
time_t rdp_get_max_retrans();


// for dgram messege transmission like UDP
//
// NOTCE:
// If the length is bigger than 896 bytes, the message is
// automatically divided and then deliverd to the
// destination unlike UDP.
// The destination node should be receive multiple times.
void send_dgram(const void *buf, int len,
uint8_t *dst);
void set_dgram_callback(dgram::callback func);
Expand Down
19 changes: 14 additions & 5 deletions src/dgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,22 @@ namespace libcage {
dgram::push2queue(id_ptr id, const void *msg, int len,
const uint160_t &src)
{
packetbuf_ptr pbuf = packetbuf::construct();
void *p;
int total = 0;
int dmax = PBUF_SIZE - PBUF_DEFAULT_OFFSET;

p = pbuf->append(len);
memcpy(p, msg, len);
while (len > 0) {
packetbuf_ptr pbuf = packetbuf::construct();
int plen = (len > dmax) ? dmax : len;
void *p;

push2queue(id, pbuf, src);
p = pbuf->append(plen);
memcpy(p, (char*)msg + total, plen);

push2queue(id, pbuf, src);

len -= plen;
total += plen;
}
}

void
Expand Down
2 changes: 1 addition & 1 deletion src/packetbuf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace libcage {

packetbuf::packetbuf() : m_len(0), m_refc(0)
{
m_head = &m_buf[128];
m_head = &m_buf[PBUF_DEFAULT_OFFSET];
}

void*
Expand Down
5 changes: 4 additions & 1 deletion src/packetbuf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
#include <boost/intrusive_ptr.hpp>
#include <boost/pool/object_pool.hpp>

#define PBUF_SIZE 1024
#define PBUF_DEFAULT_OFFSET 128

namespace libcage {
class packetbuf;

Expand Down Expand Up @@ -67,7 +70,7 @@ namespace libcage {
private:
static const int buf_max;

uint8_t m_buf[1012];
uint8_t m_buf[PBUF_SIZE];
uint8_t *m_head;
int32_t m_len;
int32_t m_refc;
Expand Down

0 comments on commit 90d4d63

Please sign in to comment.