00001
00002
00003
00004
00005
00006
00007
00008
00009
#include "wvloopback.h"
00010
00011
#ifndef _WIN32
00012
#include <sys/socket.h>
00013
#else
00014
#include <io.h>
00015
#endif
00016
#include <fcntl.h>
00017
00018
#ifdef _WIN32
00019
int socketpair (
int family,
int type,
int protocol,
int *sb);
00020
#endif
00021
00022 WvLoopback::WvLoopback()
00023 {
00024
int socks[2];
00025
00026
if (socketpair(AF_UNIX, SOCK_STREAM, 0, socks))
00027 {
00028 errnum = errno;
00029
return;
00030 }
00031
00032 rfd = socks[0];
00033 wfd = socks[1];
00034
00035
#ifndef _WIN32
00036
fcntl(rfd, F_SETFD, 1);
00037 fcntl(rfd, F_SETFL, O_RDONLY|O_NONBLOCK);
00038 fcntl(wfd, F_SETFD, 1);
00039 fcntl(wfd, F_SETFL, O_WRONLY|O_NONBLOCK);
00040
#else
00041
u_long arg = 1;
00042 ioctlsocket(rfd, FIONBIO, &arg);
00043 ioctlsocket(wfd, FIONBIO, &arg);
00044
#endif
00045
}