浏览代码

Throw string exception on stream, log on socket

Renato Golin 13 年之前
父节点
当前提交
8d83757bc1
共有 2 个文件被更改,包括 10 次插入5 次删除
  1. 4 2
      system/jlib/jsocket.cpp
  2. 6 3
      system/jlib/jstream.cpp

+ 4 - 2
system/jlib/jsocket.cpp

@@ -3561,8 +3561,10 @@ class CSocketSelectThread: public Thread
 #ifdef _USE_PIPE_FOR_SELECT_TRIGGER
         CriticalBlock block(sect);
         char c = 0;
-        if(write(dummysock[1], &c, 1) != 1)
-            throwUnexpected();
+        if(write(dummysock[1], &c, 1) != 1) {
+            int err = ERRNO();
+            LOGERR(err,1,"Socket closed during trigger select");
+        }
 #else
         closedummy();
 #endif

+ 6 - 3
system/jlib/jstream.cpp

@@ -220,13 +220,16 @@ CFileOutputStream::CFileOutputStream(int _handle)
 void CFileOutputStream::writeByte(byte b)
 {
     if (_write(handle, &b, 1) != 1)
-        throwUnexpected();
+        throw MakeStringException(-1, "Error while writing byte 0x%x\n", (unsigned)b);
 }
 
 void CFileOutputStream::writeBytes(const void *b, int len)
 {
-    if (_write(handle, b, len) != len)
-        throwUnexpected();
+    ssize_t written = _write(handle, b, len);
+    if (written < 0)
+        throw MakeStringException(-1, "Error while writing %d bytes\n", len);
+    if (written != len)
+        throw MakeStringException(-1, "Truncated (%d) while writing %d bytes\n", written, len);
 }
 
 extern jlib_decl IByteOutputStream *createOutputStream(int handle)