19 #ifndef SIMPLE_SEND_BYTES_REQUEST_CC
20 #define SIMPLE_SEND_BYTES_REQUEST_CC
29 #define HEADER_SIZE 20
34 template <
class RequestType,
class ResponseType,
class ReturnType,
class... RequestTypeParams>
39 size_t bytesForRequest,
43 RequestTypeParams&&... args) {
54 myLogger->error(errMsg);
55 myLogger->error(
"simpleSendDataRequest: not able to connect to server.\n");
56 std::cout <<
"ERROR: can't connect to remote server with port =" << port
57 <<
" and address =" << address << std::endl;
63 std::cout <<
"ERROR: block size is too small" << std::endl;
69 myLogger->error(errMsg);
70 myLogger->error(
"simpleSendDataRequest: not able to send request to server.\n");
79 if (!temp.
sendBytes(bytes, numBytes, errMsg)) {
80 myLogger->error(errMsg);
81 myLogger->error(
"simpleSendDataRequest: not able to send data to server.\n");
92 if (objectSize == 0) {
93 myLogger->error(
"simpleRequest: not able to get next object size");
94 std::cout <<
"simpleRequest: not able to get next object size" << std::endl;
102 void* memory = malloc(objectSize);
103 if (memory ==
nullptr) {
104 myLogger->error(std::string(
"FATAL ERROR: not able to allocate memory with size=") +
105 std::to_string(objectSize));
106 std::cout <<
"FATAL ERROR: not able to allocate memory" << std::endl;
109 ReturnType finalResult;
113 myLogger->error(errMsg);
114 myLogger->error(
"simpleRequest: not able to get next object over the wire.\n");
125 finalResult = processResponse(result);
size_t getSizeOfNextObject()
bool sendObject(Handle< ObjType > &sendMe, std::string &errMsg)
bool connectToInternetServer(PDBLoggerPtr logToMeIn, int portNumber, std::string serverAddress, std::string &errMsg)
bool sendBytes(void *data, size_t size, std::string &errMsg)
Handle< ObjType > getNextObject(void *readToHere, bool &success, std::string &errMsg)
ReturnType simpleSendBytesRequest(PDBLoggerPtr myLogger, int port, std::string address, ReturnType onErr, size_t bytesForRequest, function< ReturnType(Handle< ResponseType >)> processResponse, char *bytes, size_t numBytes, RequestTypeParams &&...args)
std::shared_ptr< PDBLogger > PDBLoggerPtr