improve error checking and reporting when making a tcp/ip connection.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@24168 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2006-11-29 19:57:38 +00:00
parent 92f3abe02e
commit 272d712be3
5 changed files with 45 additions and 8 deletions

View file

@ -1,3 +1,12 @@
2006-11-29 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSPrivate.h:
* Source/win32/GSFileHandleWin32.m:
* Source/Additions/GSCategories.m:
* Source/GSFileHandle.m:
Improve error checking and reporting when establishing a tcp/ip
connection.
2006-11-27 Matt Rice <ratmice@gmail.com>
* Source/NSObject.m: Fix typo.

View file

@ -929,16 +929,25 @@ strerror(int eno)
* additional information can be placed in it by higher level code.
*/
+ (NSError*) _last
{
#if defined(__MINGW32__)
return [self _systemError: GetLastError()];
#else
extern int errno;
return [self _systemError: errno];
#endif
}
+ (NSError*) _systemError: (long)code
{
NSError *error;
NSString *domain;
NSDictionary *info;
long code;
#if defined(__MINGW32__)
LPVOID lpMsgBuf;
NSString *message;
code = GetLastError();
domain = NSOSStatusErrorDomain;
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
@ -949,10 +958,8 @@ strerror(int eno)
message, NSLocalizedDescriptionKey,
nil];
#else
extern int errno;
NSString *message;
code = errno;
/* FIXME ... not all are POSIX, should we use NSMachErrorDomain for some? */
domain = NSPOSIXErrorDomain;
message = [NSString stringWithCString: strerror(code)

View file

@ -2024,17 +2024,27 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
if (operation == GSFileHandleConnectCompletionNotification
|| operation == GSSOCKSConnect)
{ // Connection attempt completed.
extern int errno;
int result;
int rval;
unsigned len = sizeof(result);
if (getsockopt(descriptor, SOL_SOCKET, SO_ERROR,
(char*)&result, &len) == 0 && result != 0)
rval = getsockopt(descriptor, SOL_SOCKET, SO_ERROR, (char*)&result, &len);
if (rval != 0)
{
NSString *s;
s = [NSString stringWithFormat: @"Connect attempt failed - %@",
[NSError _last]];
[info setObject: s forKey: GSFileHandleNotificationError];
}
else if (result != 0)
{
NSString *s;
s = [NSString stringWithFormat: @"Connect attempt failed - %@",
result, [NSError _systemError: result]];
[info setObject: s forKey: GSFileHandleNotificationError];
}
else
{

View file

@ -246,6 +246,7 @@ typedef enum {
*/
@interface NSError (GSCategories)
+ (NSError*) _last;
+ (NSError*) _systemError: (long)number;
@end
/* Used by NSException uncaught exception handler - must not call any

View file

@ -2039,16 +2039,26 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|| operation == GSSOCKSConnect)
{ // Connection attempt completed.
int result;
int rval;
unsigned len = sizeof(result);
if (getsockopt((SOCKET)_get_osfhandle(descriptor), SOL_SOCKET, SO_ERROR,
(char*)&result, &len) == 0 && result != 0)
rval = getsockopt((SOCKET)_get_osfhandle(descriptor), SOL_SOCKET,
SO_ERROR, (char*)&result, &len);
if (rval != 0)
{
NSString *s;
s = [NSString stringWithFormat: @"Connect attempt failed - %@",
[NSError _last]];
[info setObject: s forKey: GSFileHandleNotificationError];
}
else if (result != 0)
{
NSString *s;
s = [NSString stringWithFormat: @"Connect attempt failed - %@",
[NSError _systemError: result]];
[info setObject: s forKey: GSFileHandleNotificationError];
}
else
{