}
if (status < 0) {
- var ex = exceptionWithHostPort(status, 'write', req.address, req.port);
+ var ex = errnoException(status, 'write', req.error);
debug('write failure', ex);
self._destroy(ex, req.cb);
return;
explicit StreamReq(DoneCb cb) : cb_(cb) {
}
- inline void Done(int status) {
- cb_(static_cast<Req*>(this), status);
+ inline void Done(int status, const char* error_str = nullptr) {
+ Req* req = static_cast<Req*>(this);
+ Environment* env = req->env();
+ if (error_str != nullptr) {
+ req->object()->Set(env->error_string(),
+ OneByteString(env->isolate(), error_str));
+ }
+
+ cb_(req, status);
}
private:
}
-bool TLSWrap::InvokeQueued(int status) {
+bool TLSWrap::InvokeQueued(int status, const char* error_str) {
if (pending_write_items_.IsEmpty())
return false;
WriteItemList queue;
pending_write_items_.MoveBack(&queue);
while (WriteItem* wi = queue.PopFront()) {
- wi->w_->Done(status);
+ wi->w_->Done(status, error_str);
delete wi;
}
// Error or partial write
int err;
- Local<Value> arg = GetSSLError(written, &err, &error_);
+ const char* error_str = nullptr;
+ Local<Value> arg = GetSSLError(written, &err, &error_str);
if (!arg.IsEmpty()) {
MakePending();
- if (!InvokeQueued(UV_EPROTO))
- ClearError();
+ InvokeQueued(UV_EPROTO, error_str);
+ delete[] error_str;
clear_in_->Reset();
}
return 0;
}
- if (ssl_ == nullptr)
+ if (ssl_ == nullptr) {
+ ClearError();
+
+ static char msg[] = "Write after DestroySSL";
+ char* tmp = new char[sizeof(msg)];
+ memcpy(tmp, msg, sizeof(msg));
+ error_ = tmp;
return UV_EPROTO;
+ }
crypto::MarkPopErrorOnReturn mark_pop_error_on_return;
wrap->MakePending();
// And destroy
- wrap->InvokeQueued(UV_ECANCELED);
+ wrap->InvokeQueued(UV_ECANCELED, "Canceled because of SSL destruction");
// Destroy the SSL structure and friends
wrap->SSLWrap<TLSWrap>::DestroySSL();
bool ClearIn();
void ClearOut();
void MakePending();
- bool InvokeQueued(int status);
+ bool InvokeQueued(int status, const char* error_str = nullptr);
inline void Cycle() {
// Prevent recursion
--- /dev/null
+'use strict';
+const common = require('../common');
+
+if (!common.hasCrypto) {
+ console.log('1..0 # Skipped: missing crypto');
+ return;
+}
+
+const assert = require('assert');
+const https = require('https');
+const net = require('net');
+
+const server = net.createServer(function(s) {
+ s.once('data', function() {
+ s.end('I was waiting for you, hello!', function() {
+ s.destroy();
+ });
+ });
+});
+
+server.listen(common.PORT, function() {
+ const req = https.request({ port: common.PORT });
+ req.end();
+
+ req.once('error', common.mustCall(function(err) {
+ assert(/unknown protocol/.test(err.message));
+ server.close();
+ }));
+});