@@ -13,10 +13,11 @@ #define _GNU_SOURCE #import #import #import +#import #import "OFExceptions.h" #ifndef HAVE_ASPRINTF #import "asprintf.h" @@ -168,10 +169,11 @@ andMode: (const char*)mode_ { if ((self = [super initWithObject: obj])) { path = (path_ != NULL ? strdup(path_) : NULL); mode = (mode_ != NULL ? strdup(mode_) : NULL); + err = errno; } return self; } @@ -189,14 +191,20 @@ { if (string != NULL) return string; asprintf(&string, "Failed to open file %s with mode %s in object of " - "class %s!", path, mode, [self name]); + "class %s! Error string was: %s", path, mode, [self name], + strerror(err)); return string; } + +- (int)errNo +{ + return err; +} - (char*)path { return path; } @@ -230,10 +238,11 @@ { if ((self = [super initWithObject: obj])) { req_size = size; req_items = nitems; has_items = YES; + err = errno; } return self; } @@ -242,14 +251,20 @@ { if ((self = [super initWithObject: obj])) { req_size = size; req_items = 0; has_items = NO; + err = errno; } return self; } + +- (int)errNo +{ + return err; +} - (size_t)requestedSize { return req_size; } @@ -271,14 +286,16 @@ if (string != NULL) return string;; if (has_items) asprintf(&string, "Failed to read %zu items of size %zu in " - "object of class %s!", req_items, req_size, [object name]); + "object of class %s! Error string was: %s", req_items, + req_size, [object name], strerror(err)); else asprintf(&string, "Failed to read %zu bytes in object of class " - "%s!", req_size, [object name]); + "%s! Error string was: %s", req_size, [object name], + strerror(err)); return string; } @end @@ -288,14 +305,16 @@ if (string != NULL) return string; if (has_items) asprintf(&string, "Failed to write %zu items of size %zu in " - "object of class %s!", req_items, req_size, [object name]); + "object of class %s! Error string was: %s", req_items, + req_size, [object name], strerror(err)); else asprintf(&string, "Failed to write %zu bytes in object of " - "class %s!", req_size, [object name]); + "class %s! Error string was: %s", req_size, [object name], + strerror(err)); return string; } @end @@ -367,10 +386,11 @@ andService: (const char*)service_ { if ((self = [super initWithObject: obj])) { node = (node_ != NULL ? strdup(node_) : NULL); service = (service_ != NULL ? strdup(service_) : NULL); + err = errno; } return self; } @@ -391,15 +411,21 @@ asprintf(&string, "The service %s on %s could not be translated to an " "address for an object of type %s. This means that either the node " "was not found, there is no such service on the node, there was a " "problem with the name server, there was a problem with your " - "network connection or you specified an invalid node or service.", - service, node, [object name]); + "network connection or you specified an invalid node or service. " + "Error string was: %s", service, node, [object name], + strerror(err)); return string; } + +- (int)errNo +{ + return err; +} - (const char*)node { return node; } @@ -425,10 +451,11 @@ andPort: (uint16_t)port_ { if ((self = [super initWithObject: obj])) { host = (host_ != NULL ? strdup(host_) : NULL); port = port_; + err = errno; } return self; } @@ -444,14 +471,20 @@ { if (string != NULL) return string; asprintf(&string, "A connection to %s:%d could not be established in " - "object of type %s!", host, port, [object name]); + "object of type %s! Error string was: %s", host, port, + [object name], strerror(err)); return string; } + +- (int)errNo +{ + return err; +} - (const char*)host { return host; } @@ -481,10 +514,11 @@ { if ((self = [super initWithObject: obj])) { host = (host_ != NULL ? strdup(host_) : NULL); port = port_; family = family_; + err = errno; } return self; } @@ -500,14 +534,20 @@ { if (string != NULL) return string; asprintf(&string, "Binding to port %d on %s using family %d failed in " - "object of type %s!", port, host, family, [object name]); + "object of type %s! Error string was: %s", port, host, family, + [object name], strerror(err)); return string; } + +- (int)errNo +{ + return err; +} - (const char*)host { return host; } @@ -532,12 +572,14 @@ } - initWithObject: (id)obj andBackLog: (int)backlog_ { - if ((self = [super initWithObject: obj])) + if ((self = [super initWithObject: obj])) { backlog = backlog_; + err = errno; + } return self; } - (const char*)cString @@ -544,28 +586,47 @@ { if (string != NULL) return string; asprintf(&string, "Failed to listen in socket of type %s with a back " - "log of %d!", [object name], backlog); + "log of %d! Error string was: %s", [object name], backlog, + strerror(err)); return string; } + +- (int)errNo +{ + return err; +} - (int)backLog { return backlog; } @end @implementation OFAcceptFailedException +- initWithObject: (id)obj +{ + if ((self = [super initWithObject: obj])) + err = errno; + + return self; +} + - (const char*)cString { if (string != NULL) return string; - asprintf(&string, "Failed to accept connection in socket of type %s!", - [object name]); + asprintf(&string, "Failed to accept connection in socket of type %s! " + "Error string was: %s", [object name], strerror(err)); return string; } + +- (int)errNo +{ + return err; +} @end