function handleWrite() {
        try {
            if($this->data !== '') {
                $this->setErrorHandler();
                
                if($this->writeChunkSize === -1) {
                    $sent = \socket_send($this->socket, $this->data, \strlen($this->data), 0);
                } else {
                    $sent = \socket_send($this->socket, $this->data, $this->writeChunkSize, 0);
                }
                
                if($sent === false) {
                    $this->checkSocketErrors();
                }
                
                $this->restoreErrorHandler();
                
                if($sent > 0) {
                    $exceeded = isset($this->data[($this->softLimit - 1)]);
                    $this->data = (string) \substr($this->data, $sent);
                    
                    // buffer has been above limit and is now below limit
                    if($exceeded && !isset($this->data[($this->softLimit - 1)])) {
                        $this->emit('drain');
                    }
                }
            }
            
            if($this->data === '') {
                $this->removeWriteListener();
                
                if(!$this->writable) {
                    $this->close();
                }
            }
        } catch (\DomainException $error) {
            $this->restoreErrorHandler();
            
            $this->emit('error', array((new \RuntimeException('Unable to write to socket: '.$error->getMessage(), 0, $error))));
            $this->close();
        }
    }