Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBert Belder <bertbelder@gmail.com>2010-11-25 07:06:31 +0300
committerBert Belder <bertbelder@gmail.com>2010-12-21 01:51:12 +0300
commit8b9f7c6eb2452c31613c25d165fcb2c35562805a (patch)
tree83ce5363ffce7a2f46ea1614b6749e8c8804dd3f /src
parent13fb6f7fa17f3a915c25d594f4a1b638ad64f5fe (diff)
Make Read and Write in node_net.cc actually work on sockets
Diffstat (limited to 'src')
-rw-r--r--src/node_net.cc30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/node_net.cc b/src/node_net.cc
index b803fd32487..3242fa7a6a6 100644
--- a/src/node_net.cc
+++ b/src/node_net.cc
@@ -668,12 +668,26 @@ static Handle<Value> Read(const Arguments& args) {
String::New("Length is extends beyond buffer")));
}
+#ifdef __POSIX__
ssize_t bytes_read = read(fd, (char*)buffer_data + off, len);
if (bytes_read < 0) {
if (errno == EAGAIN || errno == EINTR) return Null();
return ThrowException(ErrnoException(errno, "read"));
}
+#else // __MINGW32__
+ /*
+ * read() should work for in mingw, but always gives EINVAL; someone should really file a bug about it.
+ * We'll use recv() however, it's faster as well.
+ */
+ ssize_t bytes_read = recv(_get_osfhandle(fd), (char*)buffer_data + off, len, 0);
+
+ if (bytes_read < 0) {
+ int wsaErrno = WSAGetLastError();
+ if (wsaErrno == WSAEWOULDBLOCK || wsaErrno == WSAEINTR) return Null();
+ return ThrowException(ErrnoException(wsaErrno, "read"));
+ }
+#endif
return scope.Close(Integer::New(bytes_read));
}
@@ -872,6 +886,7 @@ static Handle<Value> Write(const Arguments& args) {
String::New("Length is extends beyond buffer")));
}
+#ifdef __POSIX__
ssize_t written = write(fd, buffer_data + off, len);
if (written < 0) {
@@ -880,6 +895,21 @@ static Handle<Value> Write(const Arguments& args) {
}
return ThrowException(ErrnoException(errno, "write"));
}
+#else // __MINGW32__
+ /*
+ * write() should work for sockets in mingw, but always gives EINVAL; someone should really file a bug about it.
+ * We'll use send() however, it's faster as well.
+ */
+ ssize_t written = send(_get_osfhandle(fd), buffer_data + off, len, 0);
+
+ if (written < 0) {
+ int wsaErrno = WSAGetLastError();
+ if (errno == WSAEWOULDBLOCK || errno == WSAEINTR) {
+ return scope.Close(Integer::New(0));
+ }
+ return ThrowException(ErrnoException(wsaErrno, "write"));
+ }
+#endif // __MINGW32__
return scope.Close(Integer::New(written));
}