mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-25 09:12:24 +00:00
Change error handling to store the error number rather than the string,
and to convert to a string only on demand. This makes it possible to have the string contain the error number if we don't recognise it. [originally from svn r2548]
This commit is contained in:
parent
f9300b0011
commit
139271a71a
34
mac/otnet.c
34
mac/otnet.c
@ -13,7 +13,7 @@
|
|||||||
struct Socket_tag {
|
struct Socket_tag {
|
||||||
struct socket_function_table *fn;
|
struct socket_function_table *fn;
|
||||||
/* other stuff... */
|
/* other stuff... */
|
||||||
char *error;
|
OSStatus error;
|
||||||
EndpointRef ep;
|
EndpointRef ep;
|
||||||
Plug plug;
|
Plug plug;
|
||||||
void *private_ptr;
|
void *private_ptr;
|
||||||
@ -37,7 +37,7 @@ struct Socket_tag {
|
|||||||
typedef struct Socket_tag *Actual_Socket;
|
typedef struct Socket_tag *Actual_Socket;
|
||||||
|
|
||||||
struct SockAddr_tag {
|
struct SockAddr_tag {
|
||||||
char *error;
|
OSStatus error;
|
||||||
DNSAddress address;
|
DNSAddress address;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -64,15 +64,11 @@ void ot_cleanup(void)
|
|||||||
CloseOpenTransport();
|
CloseOpenTransport();
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *error_string(int error)
|
|
||||||
{
|
|
||||||
return "An error...";
|
|
||||||
}
|
|
||||||
|
|
||||||
SockAddr ot_namelookup(char *host, char **canonicalname)
|
SockAddr ot_namelookup(char *host, char **canonicalname)
|
||||||
{
|
{
|
||||||
SockAddr ret = smalloc(sizeof(struct SockAddr_tag));
|
SockAddr ret = smalloc(sizeof(struct SockAddr_tag));
|
||||||
|
|
||||||
|
ret->error = kOTNoError;
|
||||||
OTInitDNSAddress(&(ret->address), host);
|
OTInitDNSAddress(&(ret->address), host);
|
||||||
|
|
||||||
/* for now we'll pretend canonicalname is always just host */
|
/* for now we'll pretend canonicalname is always just host */
|
||||||
@ -172,7 +168,7 @@ Socket ot_register(void *sock, Plug plug)
|
|||||||
|
|
||||||
ret = smalloc(sizeof(struct Socket_tag));
|
ret = smalloc(sizeof(struct Socket_tag));
|
||||||
ret->fn = &fn_table;
|
ret->fn = &fn_table;
|
||||||
ret->error = NULL;
|
ret->error = kOTNoError;
|
||||||
ret->plug = plug;
|
ret->plug = plug;
|
||||||
bufchain_init(&ret->output_data);
|
bufchain_init(&ret->output_data);
|
||||||
ret->writable = 1; /* to start with */
|
ret->writable = 1; /* to start with */
|
||||||
@ -220,7 +216,7 @@ Socket ot_new(SockAddr addr, int port, int privport, int oobinline,
|
|||||||
|
|
||||||
ret = smalloc(sizeof(struct Socket_tag));
|
ret = smalloc(sizeof(struct Socket_tag));
|
||||||
ret->fn = &fn_table;
|
ret->fn = &fn_table;
|
||||||
ret->error = NULL;
|
ret->error = kOTNoError;
|
||||||
ret->plug = plug;
|
ret->plug = plug;
|
||||||
bufchain_init(&ret->output_data);
|
bufchain_init(&ret->output_data);
|
||||||
ret->connected = 0; /* to start with */
|
ret->connected = 0; /* to start with */
|
||||||
@ -241,7 +237,7 @@ Socket ot_new(SockAddr addr, int port, int privport, int oobinline,
|
|||||||
ret->ep = ep;
|
ret->ep = ep;
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
ret->error = error_string(err);
|
ret->error = err;
|
||||||
return (Socket) ret;
|
return (Socket) ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,7 +252,7 @@ Socket ot_new(SockAddr addr, int port, int privport, int oobinline,
|
|||||||
err = OTBind(ep, NULL, NULL); /* OpenTransport always picks our address */
|
err = OTBind(ep, NULL, NULL); /* OpenTransport always picks our address */
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
ret->error = error_string(err);
|
ret->error = err;
|
||||||
return (Socket) ret;
|
return (Socket) ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,7 +269,7 @@ Socket ot_new(SockAddr addr, int port, int privport, int oobinline,
|
|||||||
err = OTConnect(ep, &connectCall, nil);
|
err = OTConnect(ep, &connectCall, nil);
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
ret->error = error_string(err);
|
ret->error = err;
|
||||||
return (Socket) ret;
|
return (Socket) ret;
|
||||||
} else {
|
} else {
|
||||||
ret->connected = 1;
|
ret->connected = 1;
|
||||||
@ -374,12 +370,22 @@ static void *ot_tcp_get_private_ptr(Socket sock)
|
|||||||
*/
|
*/
|
||||||
char *ot_addr_error(SockAddr addr)
|
char *ot_addr_error(SockAddr addr)
|
||||||
{
|
{
|
||||||
return addr->error;
|
static char buf[128];
|
||||||
|
|
||||||
|
if (addr->error == kOTNoError)
|
||||||
|
return NULL;
|
||||||
|
sprintf(buf, "error %d", addr->error);
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
static char *ot_tcp_socket_error(Socket sock)
|
static char *ot_tcp_socket_error(Socket sock)
|
||||||
{
|
{
|
||||||
Actual_Socket s = (Actual_Socket) sock;
|
Actual_Socket s = (Actual_Socket) sock;
|
||||||
return s->error;
|
static char buf[128];
|
||||||
|
|
||||||
|
if (s->error == kOTNoError)
|
||||||
|
return NULL;
|
||||||
|
sprintf(buf, "error %d", s->error);
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ot_tcp_set_frozen(Socket sock, int is_frozen)
|
static void ot_tcp_set_frozen(Socket sock, int is_frozen)
|
||||||
|
Loading…
Reference in New Issue
Block a user