This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
233 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. | ||
* | ||
* 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. | ||
*/ | ||
|
||
#include "uv.h" | ||
#include "internal.h" | ||
|
||
#include <assert.h> | ||
#include <termios.h> | ||
#include <errno.h> | ||
|
||
|
||
int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd) { | ||
uv__nonblock(fd, 1); | ||
uv__stream_init(loop, (uv_stream_t*)tty, UV_TTY); | ||
uv__stream_open((uv_stream_t*)tty, fd, UV_READABLE | UV_WRITABLE); | ||
loop->counters.tty_init++; | ||
return 0; | ||
} | ||
|
||
|
||
int uv_tty_set_mode(uv_tty_t* tty, int mode) { | ||
int fd = tty->fd; | ||
struct termios orig_termios; /* in order to restore at exit */ | ||
struct termios raw; | ||
|
||
if (tcgetattr(fd, &orig_termios) == -1) goto fatal; | ||
|
||
raw = orig_termios; /* modify the original mode */ | ||
/* input modes: no break, no CR to NL, no parity check, no strip char, | ||
* no start/stop output control. */ | ||
raw.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON); | ||
/* output modes */ | ||
raw.c_oflag |= (ONLCR); | ||
/* control modes - set 8 bit chars */ | ||
raw.c_cflag |= (CS8); | ||
/* local modes - echoing off, canonical off, no extended functions, | ||
* no signal chars (^Z,^C) */ | ||
raw.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG); | ||
/* control chars - set return condition: min number of bytes and timer. | ||
* We want read to return every single byte, without timeout. */ | ||
raw.c_cc[VMIN] = 1; raw.c_cc[VTIME] = 0; /* 1 byte, no timer */ | ||
|
||
/* put terminal in raw mode after flushing */ | ||
if (tcsetattr(fd, TCSAFLUSH, &raw) < 0) goto fatal; | ||
return 0; | ||
|
||
fatal: | ||
uv_err_new(tty->loop, ENOTTY); | ||
return -1; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. | ||
* | ||
* 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. | ||
*/ | ||
|
||
#include <assert.h> | ||
|
||
#include "uv.h" | ||
#include "../uv-common.h" | ||
#include "internal.h" | ||
|
||
|
||
#ifdef _MSC_VER /* msvc */ | ||
# define NOINLINE __declspec (noinline) | ||
#else /* gcc */ | ||
# define NOINLINE __attribute__ ((noinline)) | ||
#endif | ||
|
||
|
||
static NOINLINE void uv__once_inner(uv_once_t* guard, | ||
void (*callback)(void)) { | ||
DWORD result; | ||
HANDLE existing_event, created_event; | ||
HANDLE* event_ptr; | ||
|
||
/* Fetch and align event_ptr */ | ||
event_ptr = (HANDLE*) (((uintptr_t) &guard->event + (sizeof(HANDLE) - 1)) & | ||
~(sizeof(HANDLE) - 1)); | ||
|
||
created_event = CreateEvent(NULL, 1, 0, NULL); | ||
if (created_event == 0) { | ||
/* Could fail in a low-memory situation? */ | ||
uv_fatal_error(GetLastError(), "CreateEvent"); | ||
} | ||
|
||
existing_event = InterlockedCompareExchangePointer(event_ptr, | ||
created_event, | ||
NULL); | ||
|
||
if (existing_event == NULL) { | ||
/* We won the race */ | ||
callback(); | ||
|
||
result = SetEvent(created_event); | ||
assert(result); | ||
guard->ran = 1; | ||
|
||
} else { | ||
/* We lost the race. Destroy the event we created and wait for the */ | ||
/* existing one to become signaled. */ | ||
CloseHandle(created_event); | ||
result = WaitForSingleObject(existing_event, INFINITE); | ||
assert(result == WAIT_OBJECT_0); | ||
} | ||
} | ||
|
||
|
||
void uv_once(uv_once_t* guard, void (*callback)(void)) { | ||
/* Fast case - avoid WaitForSingleObject. */ | ||
if (guard->ran) { | ||
return; | ||
} | ||
|
||
uv__once_inner(guard, callback); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. | ||
* | ||
* 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. | ||
*/ | ||
|
||
#include "uv.h" | ||
#include "internal.h" | ||
|
||
#include <assert.h> | ||
|
||
|
||
int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, uv_file fd) { | ||
assert(0 && "implement me"); | ||
return -1; | ||
} | ||
|
||
|
||
int uv_tty_set_mode(uv_tty_t* tty, int mode) { | ||
assert(0 && "implement me"); | ||
return -1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters