X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fspipe.c;h=a4f8f5fc3dd7f96e7463181e12f59569d55cc1f4;hp=f42c8f102444ba70a13f16d1810d48a1072a23ec;hb=9c32d63a1113f58ceb168e8321f1e360b2006e3b;hpb=7dc39ebcca4138d27f9a0e5082b2829a7c96375a diff --git a/src/spipe.c b/src/spipe.c index f42c8f1..a4f8f5f 100644 --- a/src/spipe.c +++ b/src/spipe.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2010 Index Data + * Copyright (C) Index Data * See the file LICENSE for details. */ @@ -49,10 +49,18 @@ #include #endif +#if HAVE_NETINET_IN_H #include +#endif +#if HAVE_NETDB_H #include +#endif +#if HAVE_ARPA_INET_H #include +#endif +#if HAVE_NETINET_TCP_H #include +#endif struct yaz_spipe { int m_fd[2]; @@ -117,7 +125,7 @@ yaz_spipe_t yaz_spipe_create(int port_to_use, WRBUF *err_msg) #endif fd_set write_set; - // create server socket + /* create server socket */ p->m_socket = socket(AF_INET, SOCK_STREAM, 0); if (p->m_socket == YAZ_INVALID_SOCKET) { @@ -129,7 +137,7 @@ yaz_spipe_t yaz_spipe_create(int port_to_use, WRBUF *err_msg) #ifndef WIN32 { unsigned long one = 1; - if (setsockopt(p->m_socket, SOL_SOCKET, SO_REUSEADDR, (char*) + if (setsockopt(p->m_socket, SOL_SOCKET, SO_REUSEADDR, (char*) &one, sizeof(one))) { if (err_msg) @@ -139,12 +147,12 @@ yaz_spipe_t yaz_spipe_create(int port_to_use, WRBUF *err_msg) } } #endif - // bind server socket + /* bind server socket */ add.sin_family = AF_INET; add.sin_port = htons(port_to_use); add.sin_addr.s_addr = INADDR_ANY; addr = ( struct sockaddr *) &add; - + if (bind(p->m_socket, addr, sizeof(struct sockaddr_in))) { if (err_msg) @@ -152,7 +160,7 @@ yaz_spipe_t yaz_spipe_create(int port_to_use, WRBUF *err_msg) yaz_spipe_destroy(p); return 0; } - + if (listen(p->m_socket, 3) < 0) { if (err_msg) @@ -161,7 +169,7 @@ yaz_spipe_t yaz_spipe_create(int port_to_use, WRBUF *err_msg) return 0; } - // client socket + /* client socket */ tmpadd = (unsigned) inet_addr("127.0.0.1"); if (!tmpadd) { @@ -170,7 +178,7 @@ yaz_spipe_t yaz_spipe_create(int port_to_use, WRBUF *err_msg) yaz_spipe_destroy(p); return 0; } - + memcpy(&add.sin_addr.s_addr, &tmpadd, sizeof(struct in_addr)); p->m_fd[1] = socket(AF_INET, SOCK_STREAM, 0); if (p->m_fd[1] == YAZ_INVALID_SOCKET) @@ -186,9 +194,9 @@ yaz_spipe_t yaz_spipe_create(int port_to_use, WRBUF *err_msg) { if ( #ifdef WIN32 - WSAGetLastError() != WSAEWOULDBLOCK + WSAGetLastError() != WSAEWOULDBLOCK #else - errno != EINPROGRESS + errno != EINPROGRESS #endif ) {