diff options
author | deva <deva> | 2005-10-18 12:07:40 +0000 |
---|---|---|
committer | deva <deva> | 2005-10-18 12:07:40 +0000 |
commit | 1099eeae24b28306022ae3663a2766261b3455e4 (patch) | |
tree | 8f40fa2017c8955e014701dd2dd19861bfe68200 /src/multicast.cc | |
parent | 38e4cbdb7aabf90d9a56ac95f1c8beca810c9436 (diff) |
*** empty log message ***
Diffstat (limited to 'src/multicast.cc')
-rw-r--r-- | src/multicast.cc | 62 |
1 files changed, 60 insertions, 2 deletions
diff --git a/src/multicast.cc b/src/multicast.cc index 34c7241..ff3f557 100644 --- a/src/multicast.cc +++ b/src/multicast.cc @@ -27,25 +27,83 @@ #include "config.h" #include "multicast.h" +#include "miav_config.h" + +#include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> -#include <sys/socket.h> #include <sys/param.h> #include <arpa/inet.h> +#include <sys/types.h> + +// For IP_MTU +//#include <linux/in.h> +//#ifndef IP_MTU +//#define IP_MTU 14 +//#endif + +#include <errno.h> Multicast::Multicast(Info *i, char *addr, int port) { info = i; + udp_buffer = NULL; + + // Open connection socket if(!UDPOpen(addr, port)) info->error("Error creating socket %s:%d", addr, port); + + int mtu = config->readInt("udp_packet_size"); + + // Create buffer with the size of MTU + // socklen_t mtu_sz; + // if(getsockopt(sock, SOL_IP, IP_MTU, &mtu, &mtu_sz) != -1) { + + udp_buffer_size = mtu - 28; + if(udp_buffer_size < 1) udp_buffer_size = 1; + udp_buffer = new char[udp_buffer_size]; + udp_buffer_pointer = udp_buffer; + info->info("UDP packet buffer size %db", udp_buffer_size); + + //} else { + // info->error("Error getting MTU size from socket: %s", strerror(errno)); + // return; + //} } Multicast::~Multicast() { + if(udp_buffer) delete udp_buffer; } void Multicast::Write(void* buf, int size) { - if(write(sock, buf, size) != size) info->error("Error Writing to socket."); + if(!udp_buffer) return; // no buffer to write in... better break out! + + // info->info("To send: %d", size); + + char *p = (char*)buf; + int left = udp_buffer_size - (udp_buffer_pointer - udp_buffer); + + while(size) { + int to_copy = size > left ? left : size; + + memcpy(udp_buffer_pointer, p, to_copy); + + left-=to_copy; + udp_buffer_pointer += to_copy; + + p+=to_copy; + size-=to_copy; + + // info->info("Copied %d - %d to go", to_copy, size); + + if(left == 0) { + // info->info("Sending full packet"); + write(sock, udp_buffer, udp_buffer_size); + left = udp_buffer_size; + udp_buffer_pointer = udp_buffer; + } + } } bool Multicast::is_address_multicast(unsigned long address) |