Commit af247189 authored by Ciarán Ó Rourke's avatar Ciarán Ó Rourke
Browse files

- Use randomly name fifo

- getDataFromFIFO no longer uses its own thread
- cleaned up some clutter
parent 9ff8651d
......@@ -5,6 +5,7 @@
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <cstdio>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
......@@ -76,14 +77,6 @@ void FiPhobo::startPutOperation(unsigned int size, std::string objectID)
// delete [] unconstedObjectID;
}
static long int fifoWriteTemp(
std::unique_ptr<folly::IOBuf> buffer, int fifo_descriptor)
{
std::cout << "IO Thread id " << std::this_thread::get_id() << std::endl;
return write(fifo_descriptor, buffer->data(), buffer->length());
}
void FiPhobo::addDataToFIFO(std::unique_ptr<folly::IOBuf> buffer)
{
#ifdef DEBUG
......@@ -106,7 +99,6 @@ void FiPhobo::addDataToFIFO(std::unique_ptr<folly::IOBuf> buffer)
}
}
void FiPhobo::finishPUT()
{
#ifdef DEBUG
......@@ -132,13 +124,10 @@ void FiPhobo::startGetOperation(std::string objectID)
#endif
startFIFO();
char* unconstedObjectID = new char[objectID.length() + 1];
// strcpy(unconstedObjectID, objectID.c_str());
descriptor.xd_objid = new char[objectID.length() + 1];
strcpy(descriptor.xd_objid, objectID.c_str());
descriptor.xd_op = PHO_XFER_OP_GET;
// descriptor.xd_objid = unconstedObjectID;
descriptor.xd_fd = fifo_descriptor;
descriptor.xd_size = 20662;
......@@ -161,22 +150,18 @@ ssize_t FiPhobo::getDataFromFIFO(void *buf, size_t count)
#ifdef DEBUG
std::cout << "Phobos_Layer::getDataFromFIFO" << std::endl;
#endif
auto readRC = std::async([fd = fifo_descriptor, buffer = buf, size = count] () {
ssize_t rc = read(fd, buffer, size);
if (rc < 0) {
ssize_t rc = read(fifo_descriptor, buf, count);
if (rc < 0) {
#ifdef DEBUG
std::cout << "getDataFromFIFO read failed" << std::endl;
std::cout << "getDataFromFIFO read failed" << std::endl;
#endif
throw fiphoexceptions::FIFOException("read", rc);
}
throw fiphoexceptions::FIFOException("read", rc);
}
#ifdef DEBUG
std::cout << "Count = " << rc << std::endl;
std::cout << "Count = " << rc << std::endl;
#endif
return rc;
});
readRC.wait();
return readRC.get();
return rc;
}
FiPhobo::~FiPhobo()
......@@ -200,6 +185,8 @@ void FiPhobo::startFIFO()
#ifdef DEBUG
std::cout << "Phobos_Layer::startFIFO" << std::endl;
#endif
fifoName = std::tmpnam(nullptr);
int rc = mkfifo(fifoName.c_str(), 0777);
if (rc < 0) {
if (errno != EEXIST) {
......
......@@ -37,11 +37,10 @@ class FiPhobo {
void startFIFO();
struct pho_xfer_desc descriptor = {0};
std::string fifoName = "/tmp/fiphoboserver_fifotemp";
std::string fifoName;
int fifo_descriptor = -1;
std::future<int> phobos_result;
std::future<long int> put_result;
std::future<std::unique_ptr<folly::IOBuf>> get_result;
bool putRunning = false;
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment