diff --git a/source/vibe/core/drivers/threadedfile.d b/source/vibe/core/drivers/threadedfile.d index 7eabfec211..d5c144bec6 100644 --- a/source/vibe/core/drivers/threadedfile.d +++ b/source/vibe/core/drivers/threadedfile.d @@ -129,7 +129,7 @@ class ThreadedFileStream : FileStream { @property int fd() { return m_fileDescriptor; } @property Path path() const { return m_path; } @property ulong size() const { return m_size; } - @property bool readable() const { return m_mode == FileMode.Read; } + @property bool readable() const { return m_mode != FileMode.Append; } @property bool writable() const { return m_mode != FileMode.Read; } void acquire() @@ -193,7 +193,8 @@ class ThreadedFileStream : FileStream { { assert(this.writable); assert(bytes.length <= int.max); - enforce(.write(m_fileDescriptor, bytes.ptr, cast(int)bytes.length) == bytes.length, "Failed to write data to disk."); + auto ret = .write(m_fileDescriptor, bytes.ptr, cast(int)bytes.length); + enforce(ret == bytes.length, "Failed to write data to disk."~to!string(bytes.length)~" "~to!string(errno)~" "~to!string(ret)~" "~to!string(m_fileDescriptor)); m_ptr += bytes.length; } diff --git a/source/vibe/db/mongo/database.d b/source/vibe/db/mongo/database.d index 03e2795eb1..545c68fed1 100644 --- a/source/vibe/db/mongo/database.d +++ b/source/vibe/db/mongo/database.d @@ -11,79 +11,80 @@ import vibe.data.bson; struct MongoDatabase { - private: + private { string m_name; MongoClient m_client; + } -package: - // http://www.mongodb.org/display/DOCS/Commands - Bson runCommand(Bson commandAndOptions) - { - return m_client.getCollection(m_name ~ ".$cmd").findOne(commandAndOptions); - } + // http://www.mongodb.org/display/DOCS/Commands + package Bson runCommand(Bson commandAndOptions) + { + return m_client.getCollection(m_name ~ ".$cmd").findOne(commandAndOptions); + } - public: - this(MongoClient client, string name) - { - import std.algorithm; + //@disable this(); - assert(client !is null); - m_client = client; + this(MongoClient client, string name) + { + import std.algorithm; - assert( - !canFind(name, '.'), - "Compound collection path provided to MongoDatabase constructor instead of single database name" - ); - m_name = name; - } + assert(client !is null); + m_client = client; - @property string name() - { - return m_name; - } + assert( + !canFind(name, '.'), + "Compound collection path provided to MongoDatabase constructor instead of single database name" + ); + m_name = name; + } - @property MongoClient client() - { - return m_client; - } + @property string name() + { + return m_name; + } - /** - * Returns: child collection of this database named "name" - */ - MongoCollection opIndex(string name) - { - return MongoCollection(this, name); - } + @property MongoClient client() + { + return m_client; + } - /** - * Returns: struct storing data from MongoDB db.getLastErrorObj() object - * - * Exact object format is not documented. MongoErrorDescription signature will be - * updated upon any issues. Note that this method will execute a query to service - * collection and thus is far from being "free". - */ - MongoErrorDescription getLastError() - { - return m_client.lockConnection().getLastError(m_name); - } + /** + * Returns: child collection of this database named "name" + */ + MongoCollection opIndex(string name) + { + return MongoCollection(this, name); + } - /* See $(LINK http://www.mongodb.org/display/DOCS/getLog+Command) - * - * Returns: Bson document with recent log messages from MongoDB service. - * Params: - * mask = "global" or "rs" or "startupWarnings". Refer to official MongoDB docs. - */ - Bson getLog(string mask) - { - return runCommand(Bson(["getLog" : Bson(mask)])); - } + /** + * Returns: struct storing data from MongoDB db.getLastErrorObj() object + * + * Exact object format is not documented. MongoErrorDescription signature will be + * updated upon any issues. Note that this method will execute a query to service + * collection and thus is far from being "free". + */ + MongoErrorDescription getLastError() + { + return m_client.lockConnection().getLastError(m_name); + } - /* See $(LINK http://www.mongodb.org/display/DOCS/fsync+Command) - * - * Returns: check documentation - */ - Bson fsync(bool async = false) - { - return runCommand(Bson(["fsync" : Bson(1), "async" : Bson(async)])); - } + /* See $(LINK http://www.mongodb.org/display/DOCS/getLog+Command) + * + * Returns: Bson document with recent log messages from MongoDB service. + * Params: + * mask = "global" or "rs" or "startupWarnings". Refer to official MongoDB docs. + */ + Bson getLog(string mask) + { + return runCommand(Bson(["getLog" : Bson(mask)])); + } + + /* See $(LINK http://www.mongodb.org/display/DOCS/fsync+Command) + * + * Returns: check documentation + */ + Bson fsync(bool async = false) + { + return runCommand(Bson(["fsync" : Bson(1), "async" : Bson(async)])); + } } diff --git a/source/vibe/http/websockets.d b/source/vibe/http/websockets.d index 2df22708ea..85b2e665b9 100644 --- a/source/vibe/http/websockets.d +++ b/source/vibe/http/websockets.d @@ -7,7 +7,7 @@ { // simple echo server while( sock.connected ){ - auto msg = sock.receive(); + auto msg = sock.receiveText(); sock.send(msg); } } @@ -171,13 +171,34 @@ class WebSocket { /** Receives a new message and returns its contents as a newly allocated data array. + + Params: + strict = If set, ensures the exact frame type (text/binary) is received and throws an execption otherwise. */ - ubyte[] receive() + ubyte[] receiveBinary(bool strict = false) { ubyte[] ret; - receive((scope message){ ret = message.readAll(); }); + receive((scope message){ + enforce(!strict || message.frameOpcode == FrameOpcode.binary, + "Expected a binary message, got "~message.frameOpcode.to!string()); + ret = message.readAll(); + }); return ret; } + /// ditto + string receiveText(bool strict = false) + { + string ret; + receive((scope message){ + enforce(!strict || message.frameOpcode == FrameOpcode.text, + "Expected a text message, got "~message.frameOpcode.to!string()); + ret = message.readAllUtf8(); + }); + return ret; + } + + /// Compatibility alias for readBinary. Will be deprecated at some point. + alias receive = receiveBinary; /** Receives a new message using an InputStream.