summaryrefslogtreecommitdiff
path: root/ace/Handle_Ops.cpp
blob: eb373af8020c7064e4a3435bd88ac10d15dc4f45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// $Id$

#include "ace/Handle_Ops.h"

#include "ace/OS_NS_errno.h"
#include "ace/OS_NS_fcntl.h"
#include "ace/Time_Value.h"

ACE_RCSID (ace,
           Handle_Ops,
           "$Id$")

ACE_HANDLE
ACE::handle_timed_open (ACE_Time_Value *timeout,
                        const ACE_TCHAR *name,
                        int flags,
                        int perms,
                        LPSECURITY_ATTRIBUTES sa)
{
  ACE_TRACE ("ACE::handle_timed_open");

  if (timeout != 0)
    {
#if !defined (ACE_WIN32)
      // On Win32, ACE_NONBLOCK gets recognized as O_WRONLY so we
      // don't use it there
      flags |= ACE_NONBLOCK;
#endif /* ACE_WIN32 */

      // Open the named pipe or file using non-blocking mode...
      ACE_HANDLE handle = ACE_OS::open (name,
                                        flags,
                                        perms,
                                        sa);
      if (handle == ACE_INVALID_HANDLE
          && (errno == EWOULDBLOCK
              && (timeout->sec () > 0 || timeout->usec () > 0)))
        // This expression checks if we were polling.
        errno = ETIMEDOUT;

      return handle;
    }
  else
    return ACE_OS::open (name, flags, perms, sa);
}