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

Try to get size from Phobos

parent 7cd0839a
......@@ -133,25 +133,35 @@ void FiPhobo::startGetOperation(std::string objectID)
startFIFO();
char* unconstedObjectID = new char[objectID.length() + 1];
strcpy(unconstedObjectID, objectID.c_str());
// 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_objid = unconstedObjectID;
descriptor.xd_fd = fifo_descriptor;
int rc = phobos_getmd_cpp(&descriptor, 1, NULL, NULL);
#ifdef DEBUG
std::cout << "Phobos object size = " << descriptor.xd_size << std::endl;
std::cout << "Starting async phobos_get_cpp" << std::endl;
#endif
phobos_result = std::async(
[&]() { return phobos_get_cpp(&descriptor, 1, NULL, NULL); });
[&]() {
std::cout << "Phobos Thread id " << std::this_thread::get_id()
<< std::endl;
return phobos_get_cpp(&descriptor, 1, NULL, NULL); });
}
std::unique_ptr<folly::IOBuf> FiPhobo::getDataFromFIFO(size_t size)
std::unique_ptr<folly::IOBuf> FiPhobo::getDataFromFIFO()
{
#ifdef DEBUG
std::cout << "Phobos_Layer::getDataFromFIFO" << std::endl;
#endif
ssize_t size = descriptor.xd_size;
get_result = std::async([&] {
std::unique_ptr<folly::IOBuf> buffer = folly::IOBuf::create(size);
int readRC = read(fifo_descriptor, buffer->writableData(), size);
......
......@@ -29,7 +29,7 @@ class FiPhobo {
void startGetOperation(std::string objectID);
std::unique_ptr<folly::IOBuf> getDataFromFIFO(size_t size);
std::unique_ptr<folly::IOBuf> getDataFromFIFO();
~FiPhobo();
......
......@@ -25,6 +25,9 @@ namespace fiphoboserver {
void GetRequestHandler::onRequest(
std::unique_ptr<proxygen::HTTPMessage> headers) noexcept
{
#ifdef DEBUG
std::cout << "Entered GetRequestHandler::onRequest" << std::endl;
#endif
if (headers->getMethod() != proxygen::HTTPMethod::GET) {
proxygen::ResponseBuilder(downstream_)
.status(400, "Bad method")
......@@ -95,7 +98,7 @@ void GetRequestHandler::readFile(folly::EventBase* evb)
std::unique_ptr<folly::IOBuf> buf;
try
{
buf = phobos.getDataFromFIFO(64);
buf = phobos.getDataFromFIFO();
}
catch(fiphoexceptions::FIFOException& fifoExcp)
{
......@@ -106,10 +109,13 @@ void GetRequestHandler::readFile(folly::EventBase* evb)
return;
}
#ifdef DEBUG
std::cout << "Sending data" << std::endl;
#endif
evb->runInEventBaseThread([this, body=std::move(buf)] () mutable {
proxygen::ResponseBuilder(downstream_)
.body(std::move(body))
.send();
.sendWithEOM();
});
}
......
......@@ -8,7 +8,7 @@
#pragma once
#include <folly/File.h>
//#include <folly/File.h>
#include <folly/Memory.h>
#include <proxygen/httpserver/RequestHandler.h>
......
......@@ -45,13 +45,25 @@ class HandlerFactory : public proxygen::RequestHandlerFactory {
proxygen::RequestHandler*,
proxygen::HTTPMessage* headers) noexcept override
{
#ifdef DEBUG
std::cout << "Choosing method: ";
#endif
if (headers->getMethod() == proxygen::HTTPMethod::GET) {
#ifdef DEBUG
std::cout << "Chose GET" << std::endl;
#endif
return new fiphoboserver::GetRequestHandler;
}
else if (headers->getMethod() == proxygen::HTTPMethod::PUT) {
#ifdef DEBUG
std::cout << "Chose PUT" << std::endl;
#endif
return new fiphoboserver::PushRequestHandler;
}
else {
#ifdef DEBUG
std::cout << "Did not choose PUT or GET" << std::endl;
#endif
return NULL;
}
}
......
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