$treeview $search $mathjax $extrastylesheet
otsdaq
v2_03_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #include "otsdaq-core/NetworkUtilities/TransceiverSocket.h" 00002 #include "otsdaq-core/Macros/CoutMacros.h" 00003 #include "otsdaq-core/MessageFacility/MessageFacility.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 // returns 0 on success 00027 int TransceiverSocket::acknowledge(const std::string& buffer, bool verbose) 00028 { 00029 // lockout other senders for the remainder of the scope 00030 std::lock_guard<std::mutex> lock(sendMutex_); 00031 00032 if(verbose) 00033 __COUT__ << "Acknowledging on Socket Descriptor #: " << socketNumber_ 00034 << " from-port: " << ntohs(socketAddress_.sin_port) 00035 << " to-port: " << ntohs(ReceiverSocket::fromAddress_.sin_port) 00036 << std::endl; 00037 00038 constexpr size_t MAX_SEND_SIZE = 65500; 00039 if(buffer.size() > MAX_SEND_SIZE) 00040 { 00041 __COUT__ << "Too large! Error writing buffer from port " 00042 << ntohs(TransmitterSocket::socketAddress_.sin_port) << ": " 00043 << std::endl; 00044 return -1; 00045 } 00046 00047 size_t offset = 0; 00048 size_t thisSize = buffer.size(); 00049 int sendToSize = sendto(socketNumber_, 00050 buffer.c_str() + offset, 00051 thisSize, 00052 0, 00053 (struct sockaddr*)&(ReceiverSocket::fromAddress_), 00054 sizeof(sockaddr_in)); 00055 00056 if(sendToSize <= 0) 00057 { 00058 __COUT__ << "Error writing buffer from port " 00059 << ntohs(TransmitterSocket::socketAddress_.sin_port) << ": " 00060 << strerror(errno) << std::endl; 00061 return -1; 00062 } 00063 00064 return 0; 00065 }