mirror of
https://github.com/janet-lang/janet
synced 2024-11-28 11:09:54 +00:00
Several changes to move pipe creation back into ev.c
This commit is contained in:
parent
2dc04d2957
commit
53aa19a916
@ -1,27 +1,4 @@
|
|||||||
/*
|
/* This will be generated by the build system if this file is not used */
|
||||||
* Copyright (c) 2020 Calvin Rose
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to
|
|
||||||
* deal in the Software without restriction, including without limitation the
|
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
||||||
* IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* This is an example janetconf.h file. This will be usually generated
|
|
||||||
* by the build system. */
|
|
||||||
|
|
||||||
#ifndef JANETCONF_H
|
#ifndef JANETCONF_H
|
||||||
#define JANETCONF_H
|
#define JANETCONF_H
|
||||||
|
@ -1622,6 +1622,54 @@ void janet_ev_sendto_string(JanetStream *stream, JanetString str, void *dest, in
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* For a pipe ID */
|
||||||
|
#ifdef JANET_WINDOWS
|
||||||
|
static volatile long PipeSerialNumber;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int janet_make_pipe(JanetHandle handles[2]) {
|
||||||
|
#ifdef JANET_WINDOWS
|
||||||
|
/*
|
||||||
|
* On windows, the built in CreatePipe function doesn't support overlapped IO
|
||||||
|
* so we lift from the windows source code and modify for our own version.
|
||||||
|
*/
|
||||||
|
JanetHandle rhandle, whandle;
|
||||||
|
UCHAR PipeNameBuffer[MAX_PATH];
|
||||||
|
sprintf(PipeNameBuffer,
|
||||||
|
"\\\\.\\Pipe\\JanetPipeFile.%08x.%08x",
|
||||||
|
GetCurrentProcessId(),
|
||||||
|
InterlockedIncrement(&PipeSerialNumber));
|
||||||
|
rhandle = CreateNamedPipeA(
|
||||||
|
PipeNameBuffer,
|
||||||
|
PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED,
|
||||||
|
PIPE_TYPE_BYTE | PIPE_WAIT,
|
||||||
|
1, /* Number of pipes */
|
||||||
|
4096, /* Out buffer size */
|
||||||
|
4096, /* In buffer size */
|
||||||
|
120 * 1000, /* Timeout in ms */
|
||||||
|
NULL);
|
||||||
|
if (!rhandle) return -1;
|
||||||
|
whandle = CreateFileA(
|
||||||
|
PipeNameBuffer,
|
||||||
|
GENERIC_WRITE,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
OPEN_EXISTING,
|
||||||
|
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
|
||||||
|
NULL);
|
||||||
|
if (whandle == INVALID_HANDLE_VALUE) {
|
||||||
|
CloseHandle(rhandle);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
handles[0] = rhandle;
|
||||||
|
handles[1] = whandle;
|
||||||
|
return 0;
|
||||||
|
#else
|
||||||
|
if (pipe(handles)) return -1;
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/* C functions */
|
/* C functions */
|
||||||
|
|
||||||
static Janet cfun_ev_go(int32_t argc, Janet *argv) {
|
static Janet cfun_ev_go(int32_t argc, Janet *argv) {
|
||||||
|
@ -1747,56 +1747,13 @@ static Janet os_open(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_abstract(janet_stream(fd, stream_flags, NULL));
|
return janet_wrap_abstract(janet_stream(fd, stream_flags, NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* For a pipe ID */
|
|
||||||
#ifdef JANET_WINDOWS
|
|
||||||
static volatile long PipeSerialNumber;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static Janet os_pipe(int32_t argc, Janet *argv) {
|
static Janet os_pipe(int32_t argc, Janet *argv) {
|
||||||
(void) argv;
|
(void) argv;
|
||||||
janet_fixarity(argc, 0);
|
janet_fixarity(argc, 0);
|
||||||
#ifdef JANET_WINDOWS
|
JanetHandle fds[2];
|
||||||
/*
|
if (janet_make_pipe(fds)) janet_panicv(janet_ev_lasterr());
|
||||||
* On windows, the built in CreatePipe function doesn't support overlapped IO
|
|
||||||
* so we lift from the windows source code and modify for our own version.
|
|
||||||
*/
|
|
||||||
JanetHandle rhandle, whandle;
|
|
||||||
UCHAR PipeNameBuffer[MAX_PATH];
|
|
||||||
sprintf(PipeNameBuffer,
|
|
||||||
"\\\\.\\Pipe\\JanetPipeFile.%08x.%08x",
|
|
||||||
GetCurrentProcessId(),
|
|
||||||
InterlockedIncrement(&PipeSerialNumber));
|
|
||||||
rhandle = CreateNamedPipeA(
|
|
||||||
PipeNameBuffer,
|
|
||||||
PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED,
|
|
||||||
PIPE_TYPE_BYTE | PIPE_WAIT,
|
|
||||||
1, /* Number of pipes */
|
|
||||||
4096, /* Out buffer size */
|
|
||||||
4096, /* In buffer size */
|
|
||||||
120 * 1000, /* Timeout in ms */
|
|
||||||
NULL);
|
|
||||||
if (!rhandle) janet_panicv(janet_ev_lasterr());
|
|
||||||
whandle = CreateFileA(
|
|
||||||
PipeNameBuffer,
|
|
||||||
GENERIC_WRITE,
|
|
||||||
0,
|
|
||||||
NULL,
|
|
||||||
OPEN_EXISTING,
|
|
||||||
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
|
|
||||||
NULL);
|
|
||||||
if (whandle == INVALID_HANDLE_VALUE) {
|
|
||||||
Janet x = janet_ev_lasterr();
|
|
||||||
CloseHandle(rhandle);
|
|
||||||
janet_panicv(x);
|
|
||||||
}
|
|
||||||
JanetStream *reader = janet_stream(rhandle, JANET_STREAM_READABLE, NULL);
|
|
||||||
JanetStream *writer = janet_stream(whandle, JANET_STREAM_WRITABLE, NULL);
|
|
||||||
#else
|
|
||||||
int fds[2];
|
|
||||||
if (pipe(fds)) janet_panicv(janet_ev_lasterr());
|
|
||||||
JanetStream *reader = janet_stream(fds[0], JANET_STREAM_READABLE, NULL);
|
JanetStream *reader = janet_stream(fds[0], JANET_STREAM_READABLE, NULL);
|
||||||
JanetStream *writer = janet_stream(fds[1], JANET_STREAM_WRITABLE, NULL);
|
JanetStream *writer = janet_stream(fds[1], JANET_STREAM_WRITABLE, NULL);
|
||||||
#endif
|
|
||||||
Janet tup[2] = {janet_wrap_abstract(reader), janet_wrap_abstract(writer)};
|
Janet tup[2] = {janet_wrap_abstract(reader), janet_wrap_abstract(writer)};
|
||||||
return janet_wrap_tuple(janet_tuple_n(tup, 2));
|
return janet_wrap_tuple(janet_tuple_n(tup, 2));
|
||||||
}
|
}
|
||||||
|
@ -145,6 +145,7 @@ extern const JanetAbstractType janet_address_type;
|
|||||||
#ifdef JANET_EV
|
#ifdef JANET_EV
|
||||||
void janet_lib_ev(JanetTable *env);
|
void janet_lib_ev(JanetTable *env);
|
||||||
void janet_ev_mark(void);
|
void janet_ev_mark(void);
|
||||||
|
int janet_make_pipe(JanetHandle handles[2]);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,12 +1,3 @@
|
|||||||
# Patch janet.h
|
# Patch janet.h
|
||||||
|
|
||||||
(def [_ janeth janetconf output] (dyn :args))
|
(def [_ janeth janetconf output] (dyn :args))
|
||||||
|
(spit output (peg/replace `#include "janetconf.h"` (slurp janetconf) (slurp janeth)))
|
||||||
(def- replace-peg
|
|
||||||
(peg/compile
|
|
||||||
~(% (* '(to `#include "janetconf.h"`)
|
|
||||||
(constant ,(slurp janetconf))
|
|
||||||
(thru `#include "janetconf.h"`)
|
|
||||||
'(any 1)))))
|
|
||||||
|
|
||||||
(spit output (first (peg/match replace-peg (slurp janeth))))
|
|
||||||
|
Loading…
Reference in New Issue
Block a user