Commit b8d04f51 authored by Sophie Wenzel-Teuber's avatar Sophie Wenzel-Teuber
Browse files

Get rid of seg fault bug

parent 1bb24039
......@@ -67,13 +67,21 @@ void FiPhobo::startPutOperation(unsigned int size, std::string objectID)
std::cout << "Starting async phobos_put_cpp" << std::endl;
#endif
phobos_result = std::async([&](){
std::cout << "Phobos Thread id " << std::this_thread::get_id() << std::endl;
return phobos_put_cpp(&descriptor, 1, NULL, NULL);
});
std::cout << "Main Thread id " << std::this_thread::get_id() << std::endl;
//TODOOOO
// 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
......@@ -81,18 +89,31 @@ void FiPhobo::addDataToFIFO(std::unique_ptr<folly::IOBuf> buffer)
#endif
if(ioRunning)
{
int ioRC = io_result.get();
if(ioRC < 0)
try
{
//TODO error handling
int ioRC = io_result.get();
if(ioRC < 0)
{
std::cout << "io async did return a bad result!" << std::endl;
//TODO error handling
}
}
catch(std::exception& e)
{
std::cerr << "Excpetion: " << e.what() << std::endl;
}
}
ioRunning = true;
buffer->coalesce();
io_result = std::async([&](){
return write(fifo_descriptor, buffer->data(), buffer->length());
});
if(buffer && buffer->data())
{
// char* tmp = new char[buffer->length()];
// memcpy(tmp, buffer->data(), buffer->length());
// std::cout << tmp << std::endl;
// buffer->coalesce();
io_result = std::async(fifoWriteTemp, std::move(buffer), fifo_descriptor);
// io_result.wait();
}
}
void FiPhobo::startGetOperation(std::string& objectID)
......@@ -123,10 +144,18 @@ std::unique_ptr<folly::IOBuf> FiPhobo::getDataFromFIFO(size_t size)
if(ioRunning)
{
int ioRC = io_result.get();
if(ioRC < 0)
try
{
//TODO error handling
int ioRC = io_result.get();
if(ioRC < 0)
{
std::cout << "io async did return a bad result!" << std::endl;
//TODO error handling
}
}
catch(std::exception& e)
{
std::cerr << "Excpetion: " << e.what() << std::endl;
}
}
ioRunning = true;
......@@ -143,17 +172,27 @@ void FiPhobo::finishIO()
#ifdef DEBUG
std::cout << "Phobos_Layer::finishIO" << std::endl;
#endif
int ioRC = io_result.get();
if(ioRC < 0)
try
{
//TODO error handling
}
int ioRC = io_result.get();
if(ioRC < 0)
{
std::cout << "io async did return a bad result!" << std::endl;
//TODO error handling
}
int phobosRC = phobos_result.get();
if(phobosRC)
int phobosRC = phobos_result.get();
if(phobosRC)
{
std::cout << "phobos async did return a bad result!" << std::endl;
//TODO error handling!
}
}
catch(std::exception& e)
{
//TODO error handling!
std::cerr << "Excpetion: " << e.what() << std::endl;
}
ioRunning = false;
}
......@@ -183,7 +222,7 @@ void FiPhobo::startFIFO()
if(rc < 0)
{
printf("mkfifo returned an error: %s\n", std::strerror(errno));
return;
// return;
}
fifo_descriptor = open(fifoName.c_str(), O_RDWR);
......
......@@ -96,7 +96,7 @@ void PushRequestHandler::onBody(std::unique_ptr<folly::IOBuf> body) noexcept
// body_ = std::move(body);
// }
#ifdef DEBUG
std::cout << "Adding data to FIFO..." << std::endl;
std::cout << "Adding data to FIFO... " << std::endl;
#endif
phobos.addDataToFIFO(std::move(body));
......@@ -118,10 +118,6 @@ void PushRequestHandler::onEOM() noexcept
std::cout << buffer << '\n';
std::cout << "End of body! \n" << std::endl;
}
else
{
std::cout << "NOPE, no body!" << std::endl;
}
#endif
try
{
......
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