Bug 1184226 - Disabling write on shutdown, r=ekr
authorMartin Thomson <martin.thomson@gmail.com>
Wed, 15 Jul 2015 12:23:10 -0700
changeset 253092 c82d87f445e33bb45bc42d08a001a59a1ef6f2ff
parent 253091 5b33e3287066c455b5ded6fc8966db19e669f431
child 253093 c211fdfbfc02fffb89dbdce4b1bf689d6c8cd07e
push id29061
push userryanvm@gmail.com
push dateThu, 16 Jul 2015 18:53:45 +0000
treeherdermozilla-central@a0f4a688433d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersekr
bugs1184226
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1184226 - Disabling write on shutdown, r=ekr
media/mtransport/transportlayerdtls.cpp
media/mtransport/transportlayerdtls.h
--- a/media/mtransport/transportlayerdtls.cpp
+++ b/media/mtransport/transportlayerdtls.cpp
@@ -97,16 +97,21 @@ int32_t TransportLayerNSPRAdapter::Recv(
 
   input_.pop();
   delete front;
 
   return count;
 }
 
 int32_t TransportLayerNSPRAdapter::Write(const void *buf, int32_t length) {
+  if (!enabled_) {
+    MOZ_MTLOG(ML_WARNING, "Writing to disabled transport layer");
+    return -1;
+  }
+
   TransportResult r = output_->SendPacket(
       static_cast<const unsigned char *>(buf), length);
   if (r >= 0) {
     return r;
   }
 
   if (r == TE_WOULDBLOCK) {
     PR_SetError(PR_WOULD_BLOCK_ERROR, 0);
@@ -195,18 +200,22 @@ static PRStatus TransportLayerBind(PRFil
 }
 
 static PRStatus TransportLayerListen(PRFileDesc *f, int32_t depth) {
   UNIMPLEMENTED;
   return PR_FAILURE;
 }
 
 static PRStatus TransportLayerShutdown(PRFileDesc *f, int32_t how) {
-  UNIMPLEMENTED;
-  return PR_FAILURE;
+  // This is only called from NSS when we are the server and the client refuses
+  // to provide a certificate.  In this case, the handshake is destined for
+  // failure, so we will just let this pass.
+  TransportLayerNSPRAdapter *io = reinterpret_cast<TransportLayerNSPRAdapter *>(f->secret);
+  io->SetEnabled(false);
+  return PR_SUCCESS;
 }
 
 // This function does not support peek, or waiting until `to`
 static int32_t TransportLayerRecv(PRFileDesc *f, void *buf, int32_t buflen,
                                   int32_t flags, PRIntervalTime to) {
   MOZ_ASSERT(flags == 0);
   if (flags != 0) {
     PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
--- a/media/mtransport/transportlayerdtls.h
+++ b/media/mtransport/transportlayerdtls.h
@@ -28,27 +28,30 @@
 namespace mozilla {
 
 struct Packet;
 
 class TransportLayerNSPRAdapter {
  public:
   explicit TransportLayerNSPRAdapter(TransportLayer *output) :
   output_(output),
-  input_() {}
+  input_(),
+  enabled_(true) {}
 
   void PacketReceived(const void *data, int32_t len);
   int32_t Recv(void *buf, int32_t buflen);
   int32_t Write(const void *buf, int32_t length);
+  void SetEnabled(bool enabled) { enabled_ = enabled; }
 
  private:
   DISALLOW_COPY_ASSIGN(TransportLayerNSPRAdapter);
 
   TransportLayer *output_;
   std::queue<Packet *> input_;
+  bool enabled_;
 };
 
 class TransportLayerDtls final : public TransportLayer {
  public:
   TransportLayerDtls() :
       role_(CLIENT),
       verification_mode_(VERIFY_UNSET),
       ssl_fd_(nullptr),