Skip to content

Commit

Permalink
Merge pull request #127 from pmdwyer/master
Browse files Browse the repository at this point in the history
Added nonblocking flag check on create file in windows impl.
  • Loading branch information
nyholku authored Jul 30, 2019
2 parents ccf20ca + bcd9034 commit d3b6903
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/jtermios/windows/JTermiosImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ public void open(String filename, int flags) throws Fail {
if (!filename.startsWith("\\\\"))
filename = "\\\\.\\" + filename;

m_Comm = CreateFile(filename, GENERIC_READ | GENERIC_WRITE, 0, null, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, null);
int openFlags = FILE_ATTRIBUTE_NORMAL;
if (((m_OpenFlags & O_NONBLOCK) != 0) || ((m_OpenFlags & O_NDELAY) != 0)) {
openFlags = FILE_FLAG_OVERLAPPED;
}
m_Comm = CreateFile(filename, GENERIC_READ | GENERIC_WRITE, 0, null, OPEN_EXISTING, openFlags, null);

if (INVALID_HANDLE_VALUE == m_Comm) {
if (GetLastError() == ERROR_FILE_NOT_FOUND)
Expand Down Expand Up @@ -224,7 +228,7 @@ public void close() {

if (m_WriteCancelObject != null && m_WriteCancelObject != NULL && m_WriteCancelObject != INVALID_HANDLE_VALUE)
CloseHandle(m_WriteCancelObject);
m_ReadCancelObject = null;
m_WriteCancelObject = null;
}

if (WaitCommEventCancelObject != null)
Expand Down
1 change: 1 addition & 0 deletions src/jtermios/windows/WinAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ public interface Windows_kernel32_lib extends StdCallLibrary {
public static final int SETBREAK = 8;
public static final int CLRBREAK = 9;

public static final int FILE_ATTRIBUTE_NORMAL = 0x00000080;
public static final int FILE_FLAG_WRITE_THROUGH = 0x80000000;
public static final int FILE_FLAG_OVERLAPPED = 0x40000000;
public static final int FILE_FLAG_NO_BUFFERING = 0x20000000;
Expand Down

0 comments on commit d3b6903

Please sign in to comment.