From cbbd3c6607570835250e8f9d9915573ca55b1a96 Mon Sep 17 00:00:00 2001 From: Kirill Volinsky Date: Sat, 2 Aug 2014 10:30:03 +0000 Subject: c files renamed to cpp git-svn-id: http://svn.miranda-ng.org/main/trunk@10014 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Gadu-Gadu/src/libgadu/win32.cpp | 65 +++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 protocols/Gadu-Gadu/src/libgadu/win32.cpp (limited to 'protocols/Gadu-Gadu/src/libgadu/win32.cpp') diff --git a/protocols/Gadu-Gadu/src/libgadu/win32.cpp b/protocols/Gadu-Gadu/src/libgadu/win32.cpp new file mode 100644 index 0000000000..55da0d8e0d --- /dev/null +++ b/protocols/Gadu-Gadu/src/libgadu/win32.cpp @@ -0,0 +1,65 @@ +//////////////////////////////////////////////////////////////////////////////// +// Gadu-Gadu Plugin for Miranda IM +// +// Copyright (c) 2003-2009 Adam Strzelecki +// Copyright (c) 2009-2010 Bartosz Białek +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +//////////////////////////////////////////////////////////////////////////////// + +#ifdef _WIN32 +#include "win32.h" + +int sockpipe(SOCKET filedes[2]) +{ + SOCKET sock; + struct sockaddr_in sin; + int len = sizeof(sin); + + filedes[0] = filedes[1] = INVALID_SOCKET; + + if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) + return -1; + + memset(&sin, 0, sizeof(sin)); + sin.sin_family = AF_INET; + sin.sin_port = htons(0); + sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + + if (bind(sock, (SOCKADDR *)&sin, len) == SOCKET_ERROR || + listen(sock, 1) == SOCKET_ERROR || + getsockname(sock, (SOCKADDR *)&sin, &len) == SOCKET_ERROR) { + closesocket(sock); + return -1; + } + + if ((filedes[1] = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET || + connect(filedes[1], (SOCKADDR *)&sin, len) == SOCKET_ERROR) { + closesocket(sock); + return -1; + } + + if ((filedes[0] = accept(sock, (SOCKADDR *)&sin, &len)) == INVALID_SOCKET) { + closesocket(filedes[1]); + filedes[1] = INVALID_SOCKET; + closesocket(sock); + return -1; + } + + closesocket(sock); + return 0; +} + +#endif /* _WIN32 */ -- cgit v1.2.3