aboutsummaryrefslogtreecommitdiff
path: root/src/platform/windows
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-03-05 17:27:04 -0800
committerGarrett D'Amore <garrett@damore.org>2018-03-05 19:39:15 -0800
commitc4da7817b4c8dd71b2a07d4d1c46b486ec57eeb4 (patch)
treeb1166d49e6673fcbad28c0bd65630f5af37a86ab /src/platform/windows
parentb6298c28473acbed2f1429176c7cae4fb514d98b (diff)
downloadnng-c4da7817b4c8dd71b2a07d4d1c46b486ec57eeb4.tar.gz
nng-c4da7817b4c8dd71b2a07d4d1c46b486ec57eeb4.tar.bz2
nng-c4da7817b4c8dd71b2a07d4d1c46b486ec57eeb4.zip
fixes #265 nngcat should support persistent ZT nodes
fixes #267 zerotier transport should lock ZT_HOME
Diffstat (limited to 'src/platform/windows')
-rw-r--r--src/platform/windows/win_debug.c13
-rw-r--r--src/platform/windows/win_file.c24
-rw-r--r--src/platform/windows/win_impl.h4
3 files changed, 35 insertions, 6 deletions
diff --git a/src/platform/windows/win_debug.c b/src/platform/windows/win_debug.c
index 00e327db..a47e7b41 100644
--- a/src/platform/windows/win_debug.c
+++ b/src/platform/windows/win_debug.c
@@ -1,5 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
+// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -83,9 +84,8 @@ nni_plat_errno(int errnum)
static struct {
int win_err;
int nng_err;
-} nni_win_errnos[] =
- {
- // clang-format off
+} nni_win_errnos[] = {
+ // clang-format off
{ ERROR_FILE_NOT_FOUND, NNG_ENOENT },
{ ERROR_PATH_NOT_FOUND, NNG_ENOENT },
{ ERROR_ACCESS_DENIED, NNG_EPERM },
@@ -104,6 +104,7 @@ static struct {
{ ERROR_NO_DATA, NNG_ECLOSED },
{ ERROR_PIPE_NOT_CONNECTED, NNG_ECLOSED },
{ ERROR_OPERATION_ABORTED, NNG_ECLOSED },
+ { ERROR_SHARING_VIOLATION, NNG_EBUSY },
{ WAIT_TIMEOUT, NNG_ETIMEDOUT },
{ WSAEINTR, NNG_EINTR },
{ WSAEBADF, NNG_ECLOSED },
@@ -143,8 +144,8 @@ static struct {
// Must be Last!!
{ 0, 0 },
- // clang-format on
- };
+ // clang-format on
+};
// This converts a Windows API error (from GetLastError()) to an
// nng standard error code.
diff --git a/src/platform/windows/win_file.c b/src/platform/windows/win_file.c
index 2a9504aa..515647e0 100644
--- a/src/platform/windows/win_file.c
+++ b/src/platform/windows/win_file.c
@@ -342,4 +342,28 @@ nni_plat_file_basename(const char *name)
return (name);
}
+int
+nni_plat_file_lock(const char *path, nni_plat_flock *lk)
+{
+ HANDLE h;
+
+ // On Windows we do not have to explicitly lock the file, the
+ // dwShareMode being set to zeor effectively prevents it.
+ h = CreateFile(path, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL, NULL);
+ if (h == INVALID_HANDLE_VALUE) {
+ return (nni_win_error(GetLastError()));
+ }
+ lk->h = h;
+ return (0);
+}
+
+void
+nni_plat_file_unlock(nni_plat_flock *lk)
+{
+ HANDLE h = lk->h;
+ (void) CloseHandle(h);
+ lk->h = INVALID_HANDLE_VALUE;
+}
+
#endif // NNG_PLATFORM_WINDOWS \ No newline at end of file
diff --git a/src/platform/windows/win_impl.h b/src/platform/windows/win_impl.h
index 0c22c240..b3c4738f 100644
--- a/src/platform/windows/win_impl.h
+++ b/src/platform/windows/win_impl.h
@@ -75,6 +75,10 @@ struct nni_win_event {
nni_win_event_ops ops;
};
+struct nni_plat_flock {
+ HANDLE h;
+};
+
extern int nni_win_error(int);
extern int nni_win_event_init(nni_win_event *, nni_win_event_ops *, void *);