This is NOT ready to be committed and in fact it may be a complete waste of
time. I had a
few minutes to hack around a couple of days back and came up with this. I did
not even
attempt to compile the unix implementation of ap_file_namedpipe_create() much
less run it.
The Windows implementation of ap_file_namedpipe_create() seems to work
I am posting this because I will unlikely have time to work on this for quite a
while and
wanted to share what I have just in case it might prove useful to someone. Use
or throw
away at your leisure...
Bill
Index: file_io/unix/pipe.c
===================================================================
RCS file: /home/cvs/apr/file_io/unix/pipe.c,v
retrieving revision 1.46
diff -u -r1.46 pipe.c
--- file_io/unix/pipe.c 2001/02/16 04:15:37 1.46
+++ file_io/unix/pipe.c 2001/06/20 18:31:01
@@ -193,17 +193,20 @@
apr_pool_cleanup_null);
return APR_SUCCESS;
}
-
-apr_status_t apr_file_namedpipe_create(const char *filename,
- apr_fileperms_t perm, apr_pool_t *cont)
+APR_DECLARE(apr_status_t) apr_file_namedpipe_create(apr_file_t **pipe,
+ const char *pipename,
+ apr_fileperms_t perm,
+ apr_pool_t *p)
{
mode_t mode = apr_unix_perms2mode(perm);
if (mkfifo(filename, mode) == -1) {
return errno;
}
- return APR_SUCCESS;
-}
+
+ return apr_file_open(pipe, pipename, flag, perm, p);
+}
+
Index: file_io/win32/open.c
===================================================================
RCS file: /home/cvs/apr/file_io/win32/open.c,v
retrieving revision 1.76
diff -u -r1.76 open.c
--- file_io/win32/open.c 2001/06/07 14:32:21 1.76
+++ file_io/win32/open.c 2001/06/20 18:31:01
@@ -169,7 +169,7 @@
return flush_rv;
}
-APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, const char *fname,
+APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, const char *name,
apr_int32_t flag, apr_fileperms_t perm,
apr_pool_t *cont)
{
@@ -177,6 +177,7 @@
* sdbm and any other random files! We _must_ rethink
* this approach.
*/
+ char *fname;
HANDLE handle = INVALID_HANDLE_VALUE;
DWORD oflags = 0;
DWORD createflags = 0;
@@ -185,6 +186,13 @@
apr_oslevel_e os_level;
apr_status_t rv;
+ if (flag & APR_PIPE_OPEN) {
+ fname = apr_psprintf(cont, "\\\\.\\pipe\\%s", name);
+ }
+ else {
+ fname = name;
+ }
+
if (flag & APR_READ) {
oflags |= GENERIC_READ;
}
@@ -293,8 +301,14 @@
(*new)->pOverlapped = (OVERLAPPED*) apr_pcalloc(cont,
sizeof(OVERLAPPED));
(*new)->pOverlapped->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
}
+
+ if (flag & APR_PIPE_OPEN) {
+ (*new)->pipe = 1;
+ }
+ else {
+ (*new)->pipe = 0;
+ }
- (*new)->pipe = 0;
(*new)->timeout = -1;
(*new)->ungetchar = -1;
(*new)->eof_hit = 0;
Index: file_io/win32/pipe.c
===================================================================
RCS file: /home/cvs/apr/file_io/win32/pipe.c,v
retrieving revision 1.37
diff -u -r1.37 pipe.c
--- file_io/win32/pipe.c 2001/06/06 16:04:54 1.37
+++ file_io/win32/pipe.c 2001/06/20 18:31:01
@@ -232,3 +232,34 @@
return APR_SUCCESS;
}
+
+APR_DECLARE(apr_status_t) apr_file_namedpipe_create(apr_file_t **pipe,
+ const char *pipename,
+ apr_fileperms_t perm,
+ apr_pool_t *p)
+{
+ SECURITY_ATTRIBUTES sa;
+
+ (*pipe) = (apr_file_t *)apr_pcalloc(p, sizeof(apr_file_t));
+ (*pipe)->cntxt = p;
+ (*pipe)->fname = apr_psprintf(p, "\\\\.\\pipe\\%s", pipename);
+ (*pipe)->pipe = 1;
+
+ sa.nLength = sizeof(sa);
+ sa.bInheritHandle = TRUE;
+ sa.lpSecurityDescriptor = NULL;
+
+ (*pipe)->filehand = CreateNamedPipe((*pipe)->fname,
+ PIPE_ACCESS_DUPLEX,
+ PIPE_TYPE_BYTE, file://dwPipeMode,
+ 1,
file://nMaxInstances,
+ 8182,
file://nOutBufferSize,
+ 8192,
file://nInBufferSize,
+ 1,
file://nDefaultTimeOut,
+ &sa);
+
+ if ((*pipe)->filehand == INVALID_HANDLE_VALUE)
+ return apr_get_os_error();
+
+ return APR_SUCCESS;
+}
Index: include/apr_file_io.h
===================================================================
RCS file: /home/cvs/apr/include/apr_file_io.h,v
retrieving revision 1.102
diff -u -r1.102 apr_file_io.h
--- include/apr_file_io.h 2001/05/31 00:11:12 1.102
+++ include/apr_file_io.h 2001/06/20 18:31:02
@@ -89,6 +89,7 @@
#define APR_SHARELOCK 1024 /* Platform dependent support for higher
level locked read/write access to support
writes across process/machines */
+#define APR_PIPE_OPEN 2048
/* flags for apr_file_seek */
#define APR_SET SEEK_SET
@@ -410,9 +411,10 @@
* @param cont The pool to operate on.
* @deffunc apr_status_t apr_file_namedpipe_create(const char *filename,
apr_fileperms_t
perm, apr_pool_t *cont)
*/
-APR_DECLARE(apr_status_t) apr_file_namedpipe_create(const char *filename,
- apr_fileperms_t perm,
- apr_pool_t *cont);
+APR_DECLARE(apr_status_t) apr_file_namedpipe_create(apr_file_t **in,
+ const char *filename,
+ apr_fileperms_t perm,
+ apr_pool_t *cont);
/**
* Get the timeout value for a pipe or manipulate the blocking state.