~ubuntu-branches/ubuntu/karmic/libevent/karmic

« back to all changes in this revision

Viewing changes to WIN32-Code/misc.c

  • Committer: Bazaar Package Importer
  • Author(s): Javier Fernandez-Sanguino Pen~a
  • Date: 2005-01-18 17:58:40 UTC
  • mfrom: (1.1.1 upstream) (2.1.1 hoary)
  • Revision ID: james.westby@ubuntu.com-20050118175840-zip9df4xnl1v7dw3
Tags: 1.0b-1.1
* NMU with maintainer's approval.
* New upstream release with backward compatibility fixes (should
  make farpd work again) (Closes: #291096)

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
        tv->tv_usec = ((int) tb.millitm) * 1000;
29
29
        return 0;
30
30
}
 
31
 
 
32
int
 
33
win_read(int fd, void *buf, unsigned int length)
 
34
{
 
35
        DWORD dwBytesRead;
 
36
        int res = ReadFile((HANDLE) fd, buf, length, &dwBytesRead, NULL);
 
37
        if (res == 0) {
 
38
                DWORD error = GetLastError();
 
39
                if (error == ERROR_NO_DATA)
 
40
                        return (0);
 
41
                return (-1);
 
42
        } else
 
43
                return (dwBytesRead);
 
44
}
 
45
 
 
46
int
 
47
win_write(int fd, void *buf, unsigned int length)
 
48
{
 
49
        DWORD dwBytesWritten;
 
50
        int res = WriteFile((HANDLE) fd, buf, length, &dwBytesWritten, NULL);
 
51
        if (res == 0) {
 
52
                DWORD error = GetLastError();
 
53
                if (error == ERROR_NO_DATA)
 
54
                        return (0);
 
55
                return (-1);
 
56
        } else
 
57
                return (dwBytesWritten);
 
58
}
 
59
 
 
60
int
 
61
socketpair(int d, int type, int protocol, int *sv)
 
62
{
 
63
        static int count;
 
64
        char buf[64];
 
65
        HANDLE fd;
 
66
        DWORD dwMode;
 
67
        sprintf(buf, "\\\\.\\pipe\\levent-%d", count++);
 
68
        /* Create a duplex pipe which will behave like a socket pair */
 
69
        fd = CreateNamedPipe(buf, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_NOWAIT, 
 
70
                PIPE_UNLIMITED_INSTANCES, 4096, 4096, 0, NULL);
 
71
        if (fd == INVALID_HANDLE_VALUE)
 
72
                return (-1);
 
73
        sv[0] = (int)fd;
 
74
 
 
75
        fd = CreateFile(buf, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
 
76
        if (fd == INVALID_HANDLE_VALUE)
 
77
                return (-1);
 
78
        dwMode = PIPE_NOWAIT;
 
79
        SetNamedPipeHandleState(fd, &dwMode, NULL, NULL);
 
80
        sv[1] = (int)fd;
 
81
 
 
82
        return (0);
 
83
}
 
 
b'\\ No newline at end of file'