--- libaitrpc/src/cli.c 2013/12/15 16:27:09 1.20.4.2 +++ libaitrpc/src/cli.c 2014/01/28 14:05:43 1.22 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: cli.c,v 1.20.4.2 2013/12/15 16:27:09 misho Exp $ +* $Id: cli.c,v 1.22 2014/01/28 14:05:43 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 +Copyright 2004 - 2014 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -236,15 +236,40 @@ err: int rpc_cli_reconnectClient(rpc_cli_t * __restrict cli) { + int netBuf; + if (!cli) return -1; + else + netBuf = AIT_LEN(&cli->cli_buf); + close(cli->cli_sock); + + cli->cli_sock = socket(cli->cli_sa.sa.sa_family, cli->cli_id, 0); + if (cli->cli_sock == -1) { + LOGERR; + return -1; + } + if (setsockopt(cli->cli_sock, SOL_SOCKET, SO_SNDBUF, + &netBuf, sizeof netBuf) == -1) { + LOGERR; + close(cli->cli_sock); + return -1; + } + if (setsockopt(cli->cli_sock, SOL_SOCKET, SO_RCVBUF, + &netBuf, sizeof netBuf) == -1) { + LOGERR; + close(cli->cli_sock); + return -1; + } if (cli->cli_id == SOCK_STREAM) if (connect(cli->cli_sock, &cli->cli_sa.sa, cli->cli_sa.sa.sa_len) == -1) { LOGERR; + close(cli->cli_sock); return -1; } + fcntl(cli->cli_sock, F_SETFL, fcntl(cli->cli_sock, F_GETFL) | O_NONBLOCK); return 0; }