Bug 1384633 - Expose the overlapped structure. r=mcmanus, temporarily accepted for 4.17, any application requiring it will break when NSPR 4.18 is released and used, r=kaie
authorDragana Damjanovic <dd.mozilla@gmail.com>
Fri, 25 Aug 2017 17:08:41 +0200
changeset 4754 6a0af7609427
parent 4753 aa88ba8082ec
child 4755 c60f6aa3770a
push id270
push userkaie@kuix.de
push date2017-08-25 15:08 +0000
reviewersmcmanus, temporarily, kaie
bugs1384633
Bug 1384633 - Expose the overlapped structure. r=mcmanus, temporarily accepted for 4.17, any application requiring it will break when NSPR 4.18 is released and used, r=kaie
pr/include/private/pprio.h
pr/src/io/prsocket.c
pr/src/nspr.def
pr/src/pthreads/ptio.c
--- a/pr/include/private/pprio.h
+++ b/pr/include/private/pprio.h
@@ -232,11 +232,25 @@ NSPR_API(void) PR_NTFast_UpdateAcceptCon
 ** DESCRIPTION:
 **    Cancel IO operations on fd.
 */
 NSPR_API(PRStatus) PR_NT_CancelIo(PRFileDesc *fd);
 
 
 #endif /* WIN32 */
 
+/* FUNCTION: PR_EXPERIMENTAL_ONLY_IN_4_17_GetOverlappedIOHandle
+** DESCRIPTION:
+** This function will be available only in nspr version 4.17
+** This functionality is only available on windows. Some windows operation use
+** asynchronous (call overlapped) io. One of them is ConnectEx. NSPR uses
+** ConnectEx for enabling TCP Fast Open.
+** This function returns an OVERLAPPED structure associated with ConnectEx call.
+** If ConnectEx has not been called or the io has already finished, the
+** function will return PR_INVALID_ARGUMENT_ERROR.
+** PRFileDesc continues to be owner of the structure and the structure must not
+** be destroyed.
+*/
+NSPR_API(PRStatus) PR_EXPERIMENTAL_ONLY_IN_4_17_GetOverlappedIOHandle(PRFileDesc *fd, void **ol);
+
 PR_END_EXTERN_C
 
 #endif /* pprio_h___ */
--- a/pr/src/io/prsocket.c
+++ b/pr/src/io/prsocket.c
@@ -1675,16 +1675,43 @@ PR_FileDesc2NativeHandle(PRFileDesc *fd)
 
 PR_IMPLEMENT(void)
 PR_ChangeFileDescNativeHandle(PRFileDesc *fd, PROsfd handle)
 {
 	if (fd)
 		fd->secret->md.osfd = handle;
 }
 
+/* Expose OVERLAPPED if present. OVERLAPPED is implemented only on WIN95. */
+PR_IMPLEMENT(PRStatus)
+PR_EXPERIMENTAL_ONLY_IN_4_17_GetOverlappedIOHandle(PRFileDesc *fd, void **ol)
+{
+#if defined(_WIN64) && defined(WIN95)
+    *ol = NULL;
+    if (fd) {
+        fd = PR_GetIdentitiesLayer(fd, PR_NSPR_IO_LAYER);
+    }
+    if (!fd) {
+        PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+        return PR_FAILURE;
+    }
+
+    if (!fd->secret->overlappedActive) {
+        PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+        return PR_FAILURE;
+    }
+
+    *ol = &fd->secret->ol;
+    return PR_SUCCESS;
+#else
+    PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
+    return PR_FAILURE;
+#endif
+}
+
 /*
 ** Select compatibility
 **
 */
 
 PR_IMPLEMENT(void) PR_FD_ZERO(PR_fd_set *set)
 {
 	memset(set, 0, sizeof(PR_fd_set));
--- a/pr/src/nspr.def
+++ b/pr/src/nspr.def
@@ -457,8 +457,12 @@ EXPORTS ;-
 ;+} NSPR_4.9.2;
 ;+# Function PR_DuplicateEnvironment had been added in NSPR 4.10.9,
 ;+# but we neglected to add it to nspr.def until NSPR 4.12
 ;+NSPR_4.12 {
 ;+      global:
 		PR_DuplicateEnvironment;
 		PR_GetEnvSecure;
 ;+} NSPR_4.10.3;
+;+NSPR_4.17 {
+;+      global:
+		PR_EXPERIMENTAL_ONLY_IN_4_17_GetOverlappedIOHandle;
+;+} NSPR_4.16;
--- a/pr/src/pthreads/ptio.c
+++ b/pr/src/pthreads/ptio.c
@@ -4739,16 +4739,24 @@ PR_IMPLEMENT(PRInt32) PR_FileDesc2Native
     PRInt32 osfd = -1;
     bottom = (NULL == bottom) ?
         NULL : PR_GetIdentitiesLayer(bottom, PR_NSPR_IO_LAYER);
     if (NULL == bottom) PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
     else osfd = bottom->secret->md.osfd;
     return osfd;
 }  /* PR_FileDesc2NativeHandle */
 
+/* Expose OVERLAPPED if present. OVERLAPPED is implemented only on WIN95. */
+PR_IMPLEMENT(PRStatus)
+PR_EXPERIMENTAL_ONLY_IN_4_17_GetOverlappedIOHandle(PRFileDesc *fd, void **ol)
+{
+    PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
+    return PR_FAILURE;
+}
+
 PR_IMPLEMENT(void) PR_ChangeFileDescNativeHandle(PRFileDesc *fd,
     PRInt32 handle)
 {
     if (fd) fd->secret->md.osfd = handle;
 }  /*  PR_ChangeFileDescNativeHandle*/
 
 PR_IMPLEMENT(PRStatus) PR_LockFile(PRFileDesc *fd)
 {