diff options
-rw-r--r-- | main/main.c | 5 | ||||
-rw-r--r-- | main/server.c | 36 | ||||
-rw-r--r-- | main/server.h | 8 | ||||
-rw-r--r-- | server/main/server.c | 34 | ||||
-rw-r--r-- | server/server.vcproj | 4 |
5 files changed, 54 insertions, 33 deletions
diff --git a/main/main.c b/main/main.c index 02aaad24..7932e860 100644 --- a/main/main.c +++ b/main/main.c @@ -147,7 +147,10 @@ int main(int argc, char ** argv) { #endif ini_services(proto, bcg); - ini_server(url, proto, bcg); + if (ini_server(url, proto, bcg) < 0) { + fprintf(stderr, "Cannot create TCF server: %s\n", errno_to_str(errno)); + exit(1); + } discovery_start(); /* Process events - must run on the initial thread since ptrace() diff --git a/main/server.c b/main/server.c index 91eed512..247d4e5f 100644 --- a/main/server.c +++ b/main/server.c @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2011 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * and Eclipse Distribution License v1.0 which accompany this distribution. @@ -18,9 +18,8 @@ #include <config.h> -#include <stdio.h> -#include <framework/errors.h> #include <framework/myalloc.h> +#include <framework/exceptions.h> #include <main/server.h> static Protocol * proto; @@ -33,23 +32,28 @@ static void channel_new_connection(ChannelServer * serv, Channel * c) { channel_start(c); } -void ini_server(const char * url, Protocol * p, TCFBroadcastGroup * b) { +int ini_server(const char * url, Protocol * p, TCFBroadcastGroup * b) { ChannelServer * serv = NULL; - PeerServer * ps = channel_peer_from_url(url); - - if (ps == NULL) { - fprintf(stderr, "Invalid server URL (-s option value): %s\n", url); - exit(1); + PeerServer * ps = NULL; + Trap trap; + + if (!set_trap(&trap)) { + bcg = NULL; + proto = NULL; + if (ps != NULL) peer_server_free(ps); + errno = trap.error; + return -1; } - peer_server_addprop(ps, loc_strdup("ServerManagerID"), loc_strdup(get_service_manager_id(p))); - - proto = p; bcg = b; + proto = p; + ps = channel_peer_from_url(url); + if (ps == NULL) str_exception(ERR_OTHER, "Invalid server URL"); + peer_server_addprop(ps, loc_strdup("ServerManagerID"), loc_strdup(get_service_manager_id(p))); serv = channel_server(ps); - if (serv == NULL) { - fprintf(stderr, "Cannot create TCF server: %s\n", errno_to_str(errno)); - exit(1); - } + if (serv == NULL) exception(errno); serv->new_conn = channel_new_connection; + + clear_trap(&trap); + return 0; } diff --git a/main/server.h b/main/server.h index 15155d57..e071cbbe 100644 --- a/main/server.h +++ b/main/server.h @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2011 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * and Eclipse Distribution License v1.0 which accompany this distribution. @@ -22,6 +22,10 @@ #include <config.h> #include <framework/protocol.h> -extern void ini_server(const char * url, Protocol * proto, TCFBroadcastGroup * bcg); +/* + * Create and start TCF server listening on the port that is described by 'url'. + * Return 0 on success, return -1 and set errno if error. + */ +extern int ini_server(const char * url, Protocol * proto, TCFBroadcastGroup * bcg); #endif /* D_server */ diff --git a/server/main/server.c b/server/main/server.c index ad375103..b4635ef4 100644 --- a/server/main/server.c +++ b/server/main/server.c @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2011 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * and Eclipse Distribution License v1.0 which accompany this distribution. @@ -18,9 +18,8 @@ #include <config.h> -#include <stdio.h> -#include <framework/errors.h> #include <framework/myalloc.h> +#include <framework/exceptions.h> #include <framework/proxy.h> #include <services/linenumbers.h> #include <services/symbols.h> @@ -69,23 +68,30 @@ static void channel_redirection_listener(Channel * host, Channel * target) { } } -void ini_server(const char * url, Protocol * p, TCFBroadcastGroup * b) { +int ini_server(const char * url, Protocol * p, TCFBroadcastGroup * b) { ChannelServer * serv = NULL; - PeerServer * ps = channel_peer_from_url(url); + PeerServer * ps = NULL; + Trap trap; - if (ps == NULL) { - fprintf(stderr, "Invalid server URL (-s option value): %s\n", url); - exit(1); + if (!set_trap(&trap)) { + bcg = NULL; + proto = NULL; + if (ps != NULL) peer_server_free(ps); + errno = trap.error; + return -1; } + + bcg = b; + proto = p; + ps = channel_peer_from_url(url); + if (ps == NULL) str_exception(ERR_OTHER, "Invalid server URL"); peer_server_addprop(ps, loc_strdup("Name"), loc_strdup("TCF Proxy")); peer_server_addprop(ps, loc_strdup("Proxy"), loc_strdup("")); - proto = p; - bcg = b; serv = channel_server(ps); - if (serv == NULL) { - fprintf(stderr, "Cannot create TCF server: %s\n", errno_to_str(errno)); - exit(1); - } + if (serv == NULL) exception(errno); serv->new_conn = channel_new_connection; + + clear_trap(&trap); add_channel_redirection_listener(channel_redirection_listener); + return 0; } diff --git a/server/server.vcproj b/server/server.vcproj index 04943e17..0b66ac5b 100644 --- a/server/server.vcproj +++ b/server/server.vcproj @@ -323,6 +323,10 @@ >
</File>
<File
+ RelativePath="..\agent\main\server.h"
+ >
+ </File>
+ <File
RelativePath="..\agent\main\services.c"
>
</File>
|