00001 #include "otsdaq-core/NetworkUtilities/TransceiverSocket.h"
00002 #include "otsdaq-core/MessageFacility/MessageFacility.h"
00003 #include "otsdaq-core/Macros/CoutMacros.h"
00004
00005 #include <iostream>
00006
00007 using namespace ots;
00008
00009
00010 TransceiverSocket::TransceiverSocket(void)
00011 {
00012 __COUT__ << "TransceiverSocket constructor " << __E__;
00013 }
00014
00015
00016 TransceiverSocket::TransceiverSocket(std::string IPAddress, unsigned int port) :
00017 Socket (IPAddress, port)
00018 {
00019 __COUT__ << "TransceiverSocket constructor " << IPAddress << ":" << port << __E__;
00020 }
00021
00022
00023 TransceiverSocket::~TransceiverSocket(void)
00024 {}
00025
00026
00027
00028
00029 int TransceiverSocket::acknowledge(const std::string& buffer,
00030 bool verbose)
00031 {
00032
00033
00034 std::lock_guard<std::mutex> lock(sendMutex_);
00035
00036
00037 if(verbose)
00038 __COUT__ << "Acknowledging on Socket Descriptor #: " << socketNumber_ <<
00039 " from-port: " << ntohs(socketAddress_.sin_port) <<
00040 " to-port: " << ntohs(ReceiverSocket::fromAddress_.sin_port) << std::endl;
00041
00042 constexpr size_t MAX_SEND_SIZE = 65500;
00043 if(buffer.size() > MAX_SEND_SIZE)
00044 {
00045 __COUT__ << "Too large! Error writing buffer from port " <<
00046 ntohs(TransmitterSocket::socketAddress_.sin_port) << ": " << std::endl;
00047 return -1;
00048 }
00049
00050 size_t offset = 0;
00051 size_t thisSize = buffer.size();
00052 int sendToSize = sendto(socketNumber_,
00053 buffer.c_str() + offset,
00054 thisSize,
00055 0,
00056 (struct sockaddr *)&(ReceiverSocket::fromAddress_), sizeof(sockaddr_in));
00057
00058
00059 if (sendToSize <= 0)
00060 {
00061 __COUT__ << "Error writing buffer from port " <<
00062 ntohs(TransmitterSocket::socketAddress_.sin_port) << ": " <<
00063 strerror(errno) << std::endl;
00064 return -1;
00065 }
00066
00067 return 0;
00068 }