X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Flpp%2Flpp_net.c;h=15ce82d7bf73e306ca6f87b2af23fc5ac6570de9;hb=4f25f9ca1fd1d53303f277a140a1aa657782aeba;hp=de91540ec5995cd4288f65822b51ca178d80e241;hpb=780ca0cd82979273de26bd01971bc5547e7aa609;p=libfirm diff --git a/ir/lpp/lpp_net.c b/ir/lpp/lpp_net.c index de91540ec..15ce82d7b 100644 --- a/ir/lpp/lpp_net.c +++ b/ir/lpp/lpp_net.c @@ -1,13 +1,28 @@ -/** - * @file lpp_net.c - * @date 19.07.2005 - * @author Sebastian Hack +/* + * Copyright (C) 2005-2011 University of Karlsruhe. All right reserved. + * + * This file is part of libFirm. + * + * This file may be distributed and/or modified under the terms of the + * GNU General Public License version 2 as published by the Free Software + * Foundation and appearing in the file LICENSE.GPL included in the + * packaging of this file. * - * A client for an lpp solving server. + * Licensees holding valid libFirm Professional Edition licenses may use + * this file in accordance with the libFirm Commercial License. + * Agreement provided with the Software. * - * Copyright (C) 2005 Universitaet Karlsruhe - * Released under the GPL + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. + */ + +/** + * @file + * @brief A client for an lpp solving server. + * @author Sebastian Hack */ +#include "config.h" #ifdef _WIN32 #include @@ -23,7 +38,6 @@ #include #include #include - #include /* solaris fix */ @@ -45,9 +59,11 @@ #include "lpp_net.h" #include "lpp_t.h" #include "lpp_comm.h" +#include "xmalloc.h" #ifdef _WIN32 -static int winsock_init(void) { +static int winsock_init(void) +{ WORD wVersionRequested; WSADATA wsaData; int err; @@ -80,31 +96,31 @@ static int winsock_init(void) { static int connect_tcp(const char *host, uint16_t port) { - struct hostent *phe; - struct protoent *ppe; - struct sockaddr_in sin; - int s; + struct hostent *phe; + struct protoent *ppe; + struct sockaddr_in sin; + int s; #ifdef _WIN32 - winsock_init(); + winsock_init(); #endif - memset(&sin, 0, sizeof(sin)); - sin.sin_family = AF_INET; - sin.sin_port = htons(port); + memset(&sin, 0, sizeof(sin)); + sin.sin_family = AF_INET; + sin.sin_port = htons(port); - if ((phe = gethostbyname(host))) - memcpy(&sin.sin_addr, phe->h_addr, phe->h_length); - else if((sin.sin_addr.s_addr = inet_addr(host)) == INADDR_NONE) { - lpp_print_err("cannot get host entry for %s", host); - return -1; - } + if ((phe = gethostbyname(host))) + memcpy(&sin.sin_addr, phe->h_addr_list[0], phe->h_length); + else if((sin.sin_addr.s_addr = inet_addr(host)) == INADDR_NONE) { + lpp_print_err("cannot get host entry for %s", host); + return -1; + } - ppe = getprotobyname("tcp"); - ERRNO_CHECK_RETURN(s = socket(PF_INET, SOCK_STREAM, ppe->p_proto), <, 0, -1); - ERRNO_CHECK_RETURN(connect(s, (struct sockaddr *) &sin, sizeof(sin)), <, 0, -1); + ppe = getprotobyname("tcp"); + ERRNO_CHECK_RETURN(s = socket(PF_INET, SOCK_STREAM, ppe->p_proto), <, 0, -1); + ERRNO_CHECK_RETURN(connect(s, (struct sockaddr *) &sin, sizeof(sin)), <, 0, -1); - return s; + return s; } char **lpp_get_solvers(const char *host) @@ -121,7 +137,7 @@ char **lpp_get_solvers(const char *host) lpp_writel(comm, LPP_CMD_SOLVERS); lpp_flush(comm); n = lpp_readl(comm); - res = malloc((n + 1) * sizeof(res[0])); + res = XMALLOCN(char*, n+1); res[n] = NULL; if(n > 0) { @@ -172,20 +188,15 @@ void lpp_solve_net(lpp_t *lpp, const char *host, const char *solver) lpp_writes(comm, solver); lpp_flush(comm); -#if 0 - ERR_CHECK_RETURN_VOID(lpp_ack(fd, sizeof(buf), buf), == 0, - ("could not set solver: %s", solver)); -#endif - t_send = ir_timer_new(); t_recv = ir_timer_new(); - ir_timer_push(t_send); + ir_timer_start(t_send); lpp_writel(comm, LPP_CMD_PROBLEM); lpp_serialize(comm, lpp, 1); lpp_serialize_values(comm, lpp, lpp_value_start); lpp_flush(comm); - ir_timer_pop(); + ir_timer_stop(t_send); lpp->send_time = ir_timer_elapsed_usec(t_send); ready = 0; @@ -196,7 +207,7 @@ void lpp_solve_net(lpp_t *lpp, const char *host, const char *solver) ir_timer_push(t_recv); lpp_deserialize_stats(comm, lpp); lpp_deserialize_values(comm, lpp, lpp_value_solution); - ir_timer_pop(); + ir_timer_stop(t_recv); lpp->recv_time = ir_timer_elapsed_usec(t_recv); ready = 1; break;