~ubuntu-branches/ubuntu/lucid/libevent/lucid

« back to all changes in this revision

Viewing changes to WIN32-Code/WIN32-Code/misc.c

  • Committer: Bazaar Package Importer
  • Author(s): Simon Law
  • Date: 2005-06-27 21:05:46 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20050627210546-ltxijf9i7ttholzh
Tags: 1.1a-1
* New upstream release.
* Acknowledge NMUs.  (Closes: Bug#288282, Bug#288404, Bug#290385, Bug#291096)
* Update README.Debian.  (Closes: Bug#310634)
* libevent.so uses a different library naming scheme now.  We will
  preserve backwards compatiblity with Debian's, but also provide symlinks
  for the official libevent-1.1a.so name.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <stdio.h>
2
 
#include <string.h>
3
 
#include <windows.h>
4
 
#include <sys/timeb.h>
5
 
#include <time.h>
6
 
 
7
 
/****************************************************************************
8
 
 *
9
 
 * Function: gettimeofday(struct timeval *, struct timezone *)
10
 
 *
11
 
 * Purpose:  Get current time of day.
12
 
 *
13
 
 * Arguments: tv => Place to store the curent time of day.
14
 
 *            tz => Ignored.
15
 
 *
16
 
 * Returns: 0 => Success.
17
 
 *
18
 
 ****************************************************************************/
19
 
 
20
 
int gettimeofday(struct timeval *tv, struct timezone *tz) {
21
 
  struct _timeb tb;
22
 
 
23
 
        if(tv == NULL)
24
 
                return -1;
25
 
 
26
 
        _ftime(&tb);
27
 
        tv->tv_sec = tb.time;
28
 
        tv->tv_usec = ((int) tb.millitm) * 1000;
29
 
        return 0;
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'