Skip to content
Snippets Groups Projects
Commit a9307909 authored by Giuseppe Lo Presti's avatar Giuseppe Lo Presti
Browse files

Added an errorcode argument to mover_open_file() plus some cosmetic changes

parent f22ae7af
No related branches found
No related tags found
No related merge requests found
......@@ -37,7 +37,7 @@
extern "C" {
/* internal function to connect to the diskmanager */
int connect_to_diskmanager(const int port) {
int connectToDiskmanager(const int port) {
// connect and send data
int sockfd = 0;
if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
......@@ -55,7 +55,7 @@ extern "C" {
/* internal function to parse the answer from the diskmanager */
void parse_answer(const int sockfd, int* rc, char** errormsg) {
void parseAnswer(const int sockfd, int* rc, char** errormsg) {
// synchronously read answer back from sockfd until \n
// Format is <returnCode> [<error message>]\n
int n = 0;
......@@ -82,42 +82,40 @@ extern "C" {
}
int mover_open_file(const int port, const char* transferMetaData, char** errormsg) {
int rc = 0;
int mover_open_file(const int port, const char* transferMetaData, int* errorcode, char** errormsg) {
*errormsg = NULL;
try {
/* Prepare open message. Protocol:
OPEN <transferMetaData>
OPEN <errorCode> <transferMetaData>
where the latter is a tuple:
(<isWriteFlag>, <tident>, <transferType>, <physicalPath> [, transferId])
*/
std::ostringstream writeBuf;
writeBuf << "OPEN " << transferMetaData;
writeBuf << "OPEN " << *errorcode << " " << transferMetaData;
try {
int sockfd = 0, n = 0;
// connect and send data
sockfd = connect_to_diskmanager(port);
sockfd = connectToDiskmanager(port);
n = write(sockfd, writeBuf.str().c_str(), writeBuf.str().length());
// process result
if (n != (int)writeBuf.str().length()) {
throw std::runtime_error("Failed to send OPEN message");
}
// synchronously read and parse answer
parse_answer(sockfd, &rc, errormsg);
parseAnswer(sockfd, errorcode, errormsg);
}
catch (std::exception& e) {
// report any exception to the caller
rc = SEINTERNAL;
*errorcode = SEINTERNAL;
*errormsg = strdup(e.what());
}
}
catch (...) {
// this is to avoid core dumps on standard exceptions
rc = SEINTERNAL;
*errorcode = SEINTERNAL;
*errormsg = strdup("mover_open_file: caught general exception");
}
return rc;
return *errorcode;
}
......@@ -139,14 +137,13 @@ extern "C" {
try {
int sockfd = 0, n = 0;
// connect and send data
sockfd = connect_to_diskmanager(port);
sockfd = connectToDiskmanager(port);
n = write(sockfd, writeBuf.str().c_str(), writeBuf.str().length());
// process result
if (n != (int)writeBuf.str().length()) {
throw std::runtime_error("Failed to send CLOSE message");
}
// synchronously read and parse answer
parse_answer(sockfd, errorcode, errormsg);
parseAnswer(sockfd, errorcode, errormsg);
}
catch (std::exception& e) {
// report any exception to the caller
......
......@@ -42,24 +42,27 @@ extern "C" {
* where tident has the format: username.clientPid:fd@clientHost
* and transferType is one of Tape, User, D2DUser, D2DInternal, D2DDraining, D2DBalance
* and transferId is missing for non-user transfers
* errorcode an error code to be passed in case of a failure; it may be filled
with a non-zero value when the operation fails
* errormsg a pointer to a buffer for the error message if the operation failed
*
* The return value is 0 for success, SETIMEDOUT if the slot had timed out meanwhile
* or SEINTERNAL for any other error.
*/
int mover_open_file(const int port, const char* transferMetaData, char** errormsg);
int mover_open_file(const int port, const char* transferMetaData, int* errorcode, char** errormsg);
/**
* mover_close_file allows a mover to close a CASTOR file after a transfer.
* It connects to the diskmanagerd daemon and synchronously wait for the response.
*
* port the port to which to connect
* transferUuid the UUID of the current transfer, aka the subRequest id
* filesize the size of the file (relevant only on Put requests)
* cksumtype the type of checksum (relevant only on Put requests)
* cksumvalue the hexadecimal value of the checksum (relevant only on Put requests)
* errorcode an error code to be passed in case of failure
* errormsg a pointer to a buffer for the error message if the operation failed
* port the port to which to connect
* transferUuid the UUID of the current transfer, aka the subRequest id
* filesize the size of the file (relevant only on Put requests)
* cksumtype the type of checksum (relevant only on Put requests)
* cksumvalue the hexadecimal value of the checksum (relevant only on Put requests)
* errorcode an error code to be passed in case of a failure; it may be filled
with a non-zero value when the operation fails
* errormsg a pointer to a buffer for the error message if the operation failed
*
* errorcode and errormsg are then populated with the result of the operation:
* if errorcode == 0 the operation was successful, otherwise errormsg contains
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment