mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +00:00
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:
parent
fa13ef9c99
commit
b8209430fd
5 changed files with 45 additions and 8 deletions
|
@ -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>
|
2006-11-27 Matt Rice <ratmice@gmail.com>
|
||||||
|
|
||||||
* Source/NSObject.m: Fix typo.
|
* Source/NSObject.m: Fix typo.
|
||||||
|
|
|
@ -929,16 +929,25 @@ strerror(int eno)
|
||||||
* additional information can be placed in it by higher level code.
|
* additional information can be placed in it by higher level code.
|
||||||
*/
|
*/
|
||||||
+ (NSError*) _last
|
+ (NSError*) _last
|
||||||
|
{
|
||||||
|
#if defined(__MINGW32__)
|
||||||
|
return [self _systemError: GetLastError()];
|
||||||
|
#else
|
||||||
|
extern int errno;
|
||||||
|
|
||||||
|
return [self _systemError: errno];
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (NSError*) _systemError: (long)code
|
||||||
{
|
{
|
||||||
NSError *error;
|
NSError *error;
|
||||||
NSString *domain;
|
NSString *domain;
|
||||||
NSDictionary *info;
|
NSDictionary *info;
|
||||||
long code;
|
|
||||||
#if defined(__MINGW32__)
|
#if defined(__MINGW32__)
|
||||||
LPVOID lpMsgBuf;
|
LPVOID lpMsgBuf;
|
||||||
NSString *message;
|
NSString *message;
|
||||||
|
|
||||||
code = GetLastError();
|
|
||||||
domain = NSOSStatusErrorDomain;
|
domain = NSOSStatusErrorDomain;
|
||||||
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
||||||
NULL, code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
NULL, code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||||
|
@ -949,10 +958,8 @@ strerror(int eno)
|
||||||
message, NSLocalizedDescriptionKey,
|
message, NSLocalizedDescriptionKey,
|
||||||
nil];
|
nil];
|
||||||
#else
|
#else
|
||||||
extern int errno;
|
|
||||||
NSString *message;
|
NSString *message;
|
||||||
|
|
||||||
code = errno;
|
|
||||||
/* FIXME ... not all are POSIX, should we use NSMachErrorDomain for some? */
|
/* FIXME ... not all are POSIX, should we use NSMachErrorDomain for some? */
|
||||||
domain = NSPOSIXErrorDomain;
|
domain = NSPOSIXErrorDomain;
|
||||||
message = [NSString stringWithCString: strerror(code)
|
message = [NSString stringWithCString: strerror(code)
|
||||||
|
|
|
@ -2024,17 +2024,27 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|
||||||
if (operation == GSFileHandleConnectCompletionNotification
|
if (operation == GSFileHandleConnectCompletionNotification
|
||||||
|| operation == GSSOCKSConnect)
|
|| operation == GSSOCKSConnect)
|
||||||
{ // Connection attempt completed.
|
{ // Connection attempt completed.
|
||||||
|
extern int errno;
|
||||||
int result;
|
int result;
|
||||||
|
int rval;
|
||||||
unsigned len = sizeof(result);
|
unsigned len = sizeof(result);
|
||||||
|
|
||||||
if (getsockopt(descriptor, SOL_SOCKET, SO_ERROR,
|
rval = getsockopt(descriptor, SOL_SOCKET, SO_ERROR, (char*)&result, &len);
|
||||||
(char*)&result, &len) == 0 && result != 0)
|
if (rval != 0)
|
||||||
{
|
{
|
||||||
NSString *s;
|
NSString *s;
|
||||||
|
|
||||||
s = [NSString stringWithFormat: @"Connect attempt failed - %@",
|
s = [NSString stringWithFormat: @"Connect attempt failed - %@",
|
||||||
[NSError _last]];
|
[NSError _last]];
|
||||||
[info setObject: s forKey: GSFileHandleNotificationError];
|
[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
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -246,6 +246,7 @@ typedef enum {
|
||||||
*/
|
*/
|
||||||
@interface NSError (GSCategories)
|
@interface NSError (GSCategories)
|
||||||
+ (NSError*) _last;
|
+ (NSError*) _last;
|
||||||
|
+ (NSError*) _systemError: (long)number;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
/* Used by NSException uncaught exception handler - must not call any
|
/* Used by NSException uncaught exception handler - must not call any
|
||||||
|
|
|
@ -2039,16 +2039,26 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|
||||||
|| operation == GSSOCKSConnect)
|
|| operation == GSSOCKSConnect)
|
||||||
{ // Connection attempt completed.
|
{ // Connection attempt completed.
|
||||||
int result;
|
int result;
|
||||||
|
int rval;
|
||||||
unsigned len = sizeof(result);
|
unsigned len = sizeof(result);
|
||||||
|
|
||||||
if (getsockopt((SOCKET)_get_osfhandle(descriptor), SOL_SOCKET, SO_ERROR,
|
rval = getsockopt((SOCKET)_get_osfhandle(descriptor), SOL_SOCKET,
|
||||||
(char*)&result, &len) == 0 && result != 0)
|
SO_ERROR, (char*)&result, &len);
|
||||||
|
if (rval != 0)
|
||||||
{
|
{
|
||||||
NSString *s;
|
NSString *s;
|
||||||
|
|
||||||
s = [NSString stringWithFormat: @"Connect attempt failed - %@",
|
s = [NSString stringWithFormat: @"Connect attempt failed - %@",
|
||||||
[NSError _last]];
|
[NSError _last]];
|
||||||
[info setObject: s forKey: GSFileHandleNotificationError];
|
[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
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue