- dump winsize info too.

- prepare for VTIME and VMIN handling: allow waiting with timeout.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25405 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
François Revol
2008-05-09 21:48:59 +00:00
parent 536f5d515a
commit 4b48c06f26
2 changed files with 25 additions and 11 deletions
+24 -10
View File
@@ -135,6 +135,7 @@ class ReaderLocker : public AbstractLocker {
ReaderLocker(tty_cookie *cookie); ReaderLocker(tty_cookie *cookie);
~ReaderLocker(); ~ReaderLocker();
status_t AcquireReader(bigtime_t timeout);
status_t AcquireReader(bool dontBlock); status_t AcquireReader(bool dontBlock);
private: private:
@@ -393,7 +394,7 @@ RequestOwner::SetBytesNeeded(size_t bytesNeeded)
* The request lock MUST NOT be held! * The request lock MUST NOT be held!
*/ */
status_t status_t
RequestOwner::Wait(bool interruptable) RequestOwner::Wait(bool interruptable, bigtime_t timeout)
{ {
TRACE(("%p->RequestOwner::Wait(%d)\n", this, interruptable)); TRACE(("%p->RequestOwner::Wait(%d)\n", this, interruptable));
@@ -420,7 +421,7 @@ RequestOwner::Wait(bool interruptable)
// wait // wait
TRACE(("%p->RequestOwner::Wait(): waiting for condition...\n", this)); TRACE(("%p->RequestOwner::Wait(): waiting for condition...\n", this));
error = entry.Wait(); error = entry.Wait(B_RELATIVE_TIMEOUT, timeout);
TRACE(("%p->RequestOwner::Wait(): condition occurred: %lx\n", this, TRACE(("%p->RequestOwner::Wait(): condition occurred: %lx\n", this,
error)); error));
@@ -677,7 +678,7 @@ ReaderLocker::~ReaderLocker()
status_t status_t
ReaderLocker::AcquireReader(bool dontBlock) ReaderLocker::AcquireReader(bigtime_t timeout)
{ {
if (fCookie->closed) if (fCookie->closed)
return B_FILE_ERROR; return B_FILE_ERROR;
@@ -695,12 +696,12 @@ ReaderLocker::AcquireReader(bool dontBlock)
// We are not the first in queue or currently there's nothing to read: // We are not the first in queue or currently there's nothing to read:
// bail out, if we shall not block. // bail out, if we shall not block.
if (dontBlock) if (timeout <= 0)
return B_WOULD_BLOCK; return B_WOULD_BLOCK;
// block until something happens // block until something happens
Unlock(); Unlock();
status = fRequestOwner.Wait(true); status = fRequestOwner.Wait(true, timeout);
Lock(); Lock();
if (status == B_OK) if (status == B_OK)
@@ -713,6 +714,13 @@ ReaderLocker::AcquireReader(bool dontBlock)
} }
status_t
ReaderLocker::AcquireReader(bool dontBlock)
{
return AcquireReader(dontBlock ? 0 : B_INFINITE_TIMEOUT);
}
size_t size_t
ReaderLocker::_CheckAvailableBytes() const ReaderLocker::_CheckAvailableBytes() const
{ {
@@ -1456,8 +1464,9 @@ tty_ioctl(tty_cookie *cookie, uint32 op, void *buffer, size_t length)
case TCWAITEVENT: // BeOS (uint *) case TCWAITEVENT: // BeOS (uint *)
// wait for event (timeout if !NULL) // wait for event (timeout if !NULL)
case TCVTIME: // BeOS (bigtime_t *) set highrez VTIME case TCVTIME: // BeOS (bigtime_t *) set highrez VTIME
case 'ochr': // BeOS (int *) same as ichr for write
dprintf("tty: unsupported legacy opcode %lu\n", op); dprintf("tty: unsupported legacy opcode %lu\n", op);
// TODO; // TODO ?
break; break;
case TCXONC: // Unix, but even Linux doesn't handle it case TCXONC: // Unix, but even Linux doesn't handle it
@@ -1465,7 +1474,6 @@ tty_ioctl(tty_cookie *cookie, uint32 op, void *buffer, size_t length)
break; break;
case TCQUERYCONNECTED: // BeOS case TCQUERYCONNECTED: // BeOS
case 'ochr': // BeOS (int *) same as ichr for write
dprintf("tty: unsupported legacy opcode %lu\n", op); dprintf("tty: unsupported legacy opcode %lu\n", op);
// BeOS didn't implement them anyway // BeOS didn't implement them anyway
break; break;
@@ -1492,6 +1500,9 @@ tty_input_read(tty_cookie *cookie, void *buffer, size_t *_length)
bool dontBlock = (mode & O_NONBLOCK) != 0; bool dontBlock = (mode & O_NONBLOCK) != 0;
size_t length = *_length; size_t length = *_length;
ssize_t bytesRead = 0; ssize_t bytesRead = 0;
bigtime_t timeout = dontBlock ? 0 : B_INFINITE_TIMEOUT;
bigtime_t vtime = 0LL;
size_t vmin = 0;
TRACE(("tty_input_read(tty = %p, length = %lu, mode = %lu)\n", tty, length, mode)); TRACE(("tty_input_read(tty = %p, length = %lu, mode = %lu)\n", tty, length, mode));
@@ -1506,7 +1517,7 @@ tty_input_read(tty_cookie *cookie, void *buffer, size_t *_length)
ReaderLocker locker(cookie); ReaderLocker locker(cookie);
while (bytesRead == 0) { while (bytesRead == 0) {
status_t status = locker.AcquireReader(dontBlock); status_t status = locker.AcquireReader(timeout);
if (status != B_OK) { if (status != B_OK) {
*_length = 0; *_length = 0;
return status; return status;
@@ -1620,6 +1631,8 @@ tty_write_to_tty_master_unsafe(tty_cookie *sourceCookie, const char *data,
writable = locker.AvailableBytes(); writable = locker.AvailableBytes();
// XXX: do we need to support VMIN & VTIME for write() ?
// We need to restart the loop, since the termios flags might have // We need to restart the loop, since the termios flags might have
// changed in the meantime (while we've unlocked the tty). Note, // changed in the meantime (while we've unlocked the tty). Note,
// that we don't re-get "echo" -- maybe we should. // that we don't re-get "echo" -- maybe we should.
@@ -1911,8 +1924,9 @@ dump_tty_settings(struct tty_settings& settings)
kprintf(" pgrp_id: %ld\n", settings.pgrp_id); kprintf(" pgrp_id: %ld\n", settings.pgrp_id);
kprintf(" session_id: %ld\n", settings.session_id); kprintf(" session_id: %ld\n", settings.session_id);
// struct termios termios; // struct termios termios;
// struct winsize window_size; kprintf(" wsize: %u x %u c, %u x %u pxl\n",
settings.window_size.ws_row, settings.window_size.ws_col,
settings.window_size.ws_xpixel, settings.window_size.ws_ypixel);
} }
static void static void
+1 -1
View File
@@ -91,7 +91,7 @@ class RequestOwner {
void SetBytesNeeded(size_t bytesNeeded); void SetBytesNeeded(size_t bytesNeeded);
size_t BytesNeeded() const { return fBytesNeeded; } size_t BytesNeeded() const { return fBytesNeeded; }
status_t Wait(bool interruptable); status_t Wait(bool interruptable, bigtime_t timeout=B_INFINITE_TIMEOUT);
bool IsFirstInQueues(); bool IsFirstInQueues();