Exemplo n.º 1
0
 public function send(socket $socket, request $request)
 {
     if ($this->has_cookie()) {
         $request->add_header('Cookie', $this->get_cookie_header());
     }
     $request_message = $request->fetch();
     // echo $request_message;
     $socket->write($request_message);
     $response = new response($socket->read());
     $cookies = $response->get_header('Set-Cookie');
     if ($cookies !== null) {
         if (is_array($cookies)) {
             foreach ($cookies as $cookie) {
                 $this->parse_cookie($cookie);
             }
         } else {
             $this->parse_cookie($cookies);
         }
     }
     return $response;
 }
Exemplo n.º 2
0
 public function do_write()
 {
     $length = strlen($this->write_buffer);
     try {
         $written = parent::write($this->write_buffer, $length);
         if ($written < $length) {
             $this->write_buffer = substr($this->write_buffer, $written);
         } else {
             $this->write_buffer = '';
         }
         $this->on_write();
         return true;
     } catch (socketException $e) {
         $old_socket = (int) $this->socket;
         $this->close();
         $this->socket = $old_socket;
         $this->disconnected = true;
         $this->on_disconnect();
         return false;
     }
     return false;
 }