Skip to content

Commit d3b6903

Browse files
authored
Merge pull request #127 from pmdwyer/master
Added nonblocking flag check on create file in windows impl.
2 parents ccf20ca + bcd9034 commit d3b6903

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/jtermios/windows/JTermiosImpl.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,11 @@ public void open(String filename, int flags) throws Fail {
137137
if (!filename.startsWith("\\\\"))
138138
filename = "\\\\.\\" + filename;
139139

140-
m_Comm = CreateFile(filename, GENERIC_READ | GENERIC_WRITE, 0, null, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, null);
140+
int openFlags = FILE_ATTRIBUTE_NORMAL;
141+
if (((m_OpenFlags & O_NONBLOCK) != 0) || ((m_OpenFlags & O_NDELAY) != 0)) {
142+
openFlags = FILE_FLAG_OVERLAPPED;
143+
}
144+
m_Comm = CreateFile(filename, GENERIC_READ | GENERIC_WRITE, 0, null, OPEN_EXISTING, openFlags, null);
141145

142146
if (INVALID_HANDLE_VALUE == m_Comm) {
143147
if (GetLastError() == ERROR_FILE_NOT_FOUND)
@@ -224,7 +228,7 @@ public void close() {
224228

225229
if (m_WriteCancelObject != null && m_WriteCancelObject != NULL && m_WriteCancelObject != INVALID_HANDLE_VALUE)
226230
CloseHandle(m_WriteCancelObject);
227-
m_ReadCancelObject = null;
231+
m_WriteCancelObject = null;
228232
}
229233

230234
if (WaitCommEventCancelObject != null)

src/jtermios/windows/WinAPI.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ public interface Windows_kernel32_lib extends StdCallLibrary {
309309
public static final int SETBREAK = 8;
310310
public static final int CLRBREAK = 9;
311311

312+
public static final int FILE_ATTRIBUTE_NORMAL = 0x00000080;
312313
public static final int FILE_FLAG_WRITE_THROUGH = 0x80000000;
313314
public static final int FILE_FLAG_OVERLAPPED = 0x40000000;
314315
public static final int FILE_FLAG_NO_BUFFERING = 0x20000000;

0 commit comments

Comments
 (0)