public int fcntl(int fd, int cmd, int arg) { Port port = getPort(fd); if (port == null) return -1; if (F_SETFL == cmd) port.m_OpenFlags = arg; else if (F_GETFL == cmd) return port.m_OpenFlags; else { m_ErrNo = ENOTSUP; return -1; } return 0; }
public int open(String filename, int flags) { Port port = new Port(); port.m_OpenFlags = flags; try { if (!filename.startsWith("\\\\")) filename = "\\\\.\\" + filename; port.m_Comm = CreateFileW( new WString(filename), GENERIC_READ | GENERIC_WRITE, 0, null, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, null); if (INVALID_HANDLE_VALUE == port.m_Comm) { if (GetLastError() == ERROR_FILE_NOT_FOUND) m_ErrNo = ENOENT; else m_ErrNo = EBUSY; port.fail(); } if (!SetupComm(port.m_Comm, (int) port.m_RdBuffer.size(), (int) port.m_WrBuffer.size())) port.fail(); // FIXME what would be appropriate error code here cfmakeraw(port.m_Termios); cfsetispeed(port.m_Termios, B9600); cfsetospeed(port.m_Termios, B9600); port.m_Termios.c_cc[VTIME] = 0; port.m_Termios.c_cc[VMIN] = 0; updateFromTermios(port); port.m_RdOVL.writeField("hEvent", CreateEventA(null, true, false, null)); if (port.m_RdOVL.hEvent == INVALID_HANDLE_VALUE) port.fail(); port.m_WrOVL.writeField("hEvent", CreateEventA(null, true, false, null)); if (port.m_WrOVL.hEvent == INVALID_HANDLE_VALUE) port.fail(); port.m_SelOVL.writeField("hEvent", CreateEventA(null, true, false, null)); if (port.m_SelOVL.hEvent == INVALID_HANDLE_VALUE) port.fail(); return port.m_FD; } catch (Exception f) { if (port != null) port.close(); return -1; } }