diff options
| author | Adam <Adam@anope.org> | 2011-11-08 17:29:16 -0500 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2011-11-08 17:29:16 -0500 |
| commit | b5ff856f47d8e54d12c568462a06351633c29610 (patch) | |
| tree | a4e2f96c59ee49aa5e6cacdfd30db6155151ad36 /src/win32/pipe | |
| parent | 97b9055f92f21cd91af44a3d5dacce0024536cff (diff) | |
Windows
Diffstat (limited to 'src/win32/pipe')
| -rw-r--r-- | src/win32/pipe/pipe.cpp | 61 | ||||
| -rw-r--r-- | src/win32/pipe/pipe.h | 8 |
2 files changed, 69 insertions, 0 deletions
diff --git a/src/win32/pipe/pipe.cpp b/src/win32/pipe/pipe.cpp new file mode 100644 index 000000000..94e204d9a --- /dev/null +++ b/src/win32/pipe/pipe.cpp @@ -0,0 +1,61 @@ + /* POSIX emulation layer for Windows. + * + * Copyright (C) 2008-2011 Anope Team <team@anope.org> + * + * Please read COPYING and README for further details. + */ + +#include "services.h" + +int pipe(int fds[2]) +{ + sockaddrs localhost; + + localhost.pton(AF_INET, "127.0.0.1"); + + int cfd = socket(AF_INET, SOCK_STREAM, 0), lfd = socket(AF_INET, SOCK_STREAM, 0); + if (cfd == -1 || lfd == -1) + { + close(cfd); + close(lfd); + return -1; + } + + if (bind(lfd, &localhost.sa, localhost.size()) == -1) + { + close(cfd); + close(lfd); + return -1; + } + + if (listen(lfd, 1) == -1) + { + close(cfd); + close(lfd); + return -1; + } + + sockaddrs lfd_addr; + socklen_t sz = sizeof(lfd_addr); + getsockname(lfd, &lfd_addr.sa, &sz); + + if (connect(cfd, &lfd_addr.sa, lfd_addr.size())) + { + close(cfd); + close(lfd); + return -1; + } + + int afd = accept(lfd, NULL, NULL); + if (afd == -1) + { + close(cfd); + return -1; + } + + fds[0] = cfd; + fds[1] = afd; + + return 0; +} + diff --git a/src/win32/pipe/pipe.h b/src/win32/pipe/pipe.h new file mode 100644 index 000000000..1e8538cfb --- /dev/null +++ b/src/win32/pipe/pipe.h @@ -0,0 +1,8 @@ + /* POSIX emulation layer for Windows. + * + * Copyright (C) 2008-2011 Anope Team <team@anope.org> + * + * Please read COPYING and README for further details. + */ + +extern int pipe(int fds[2]); |
