00001 #include "otsdaq-core/NetworkUtilities/TransmitterSocket.h"
00002 #include "otsdaq-core/MessageFacility/MessageFacility.h"
00003 #include "otsdaq-core/Macros/CoutHeaderMacros.h"
00004
00005 #include <iostream>
00006
00007 using namespace ots;
00008
00009
00010 TransmitterSocket::TransmitterSocket(void)
00011 {
00012 __MOUT__ << std::endl;
00013 }
00014
00015
00016 TransmitterSocket::TransmitterSocket(const std::string &IPAddress, unsigned int port)
00017 : Socket(IPAddress, port)
00018 {
00019 __MOUT__ << std::endl;
00020 }
00021
00022
00023 TransmitterSocket::~TransmitterSocket(void)
00024 {
00025 }
00026
00027
00028 int TransmitterSocket::send(Socket& toSocket, const std::string& buffer)
00029 {
00030
00031
00032 std::lock_guard<std::mutex> lock(sendMutex_);
00033
00034
00035
00036
00037
00038 if(sendto(socketNumber_, buffer.c_str(), buffer.size(), 0,
00039 (struct sockaddr *)&(toSocket.getSocketAddress()),
00040 sizeof(sockaddr_in)) < (int)(buffer.size()))
00041 {
00042 __MOUT__ << "Error writing buffer for port " << ntohs(socketAddress_.sin_port) << std::endl;
00043 return -1;
00044 }
00045 return 0;
00046 }
00047
00048
00049 int TransmitterSocket::send(Socket& toSocket, const std::vector<uint32_t>& buffer)
00050 {
00051
00052 std::lock_guard<std::mutex> lock(sendMutex_);
00053
00054
00055
00056
00057
00058 if(sendto(socketNumber_, &buffer[0], buffer.size()*sizeof(uint32_t), 0, (struct sockaddr *)&(toSocket.getSocketAddress()), sizeof(sockaddr_in)) < (int)(buffer.size()*sizeof(uint32_t)))
00059 {
00060 __MOUT__ << "Error writing buffer for port " << ntohs(socketAddress_.sin_port) << std::endl;
00061 return -1;
00062 }
00063 return 0;
00064
00065 }