Sends a chunk
@param $request
@param $chunk
@return bool
428890
protected function sendChunk($request, $chunk)
    {
        $paddingLength = 8 - strlen($chunk) % 8;
        $payload = "\x01" // protocol version
         . "\x06" // record type (STDOUT)
         . pack('nnC', $request->id, strlen($chunk), $paddingLength) // id, content length, padding length
         . "\x00" // reserved
         . $chunk // content
         . str_repeat("\0", $paddingLength);

        return $this->send($request->fd, $payload);
    }
355253
public function write ( $chunk ) {
			if( $this->write_finished ) { throw new InvalidOperationException( "Can not write, reading has started." ); }

			if( ! $this->write_started ) {
				fwrite( $this->socket, "\r\n" ); // Start message body
				$this->write_started = true;
			}
	
			fwrite( $this->socket, sprintf( "%x\r\n", strlen( $chunk ) ) );
			fwrite( $this->socket, $chunk );
			fwrite( $this->socket, "\r\n" );
			fflush( $this->socket );
		}
336953
protected function insert_chunk($table, array $chunk, array $columns) {
        $fieldssql = '('.implode(',', array_keys($columns)).')';

        $valuessql = '('.implode(',', array_fill(0, count($columns), '?')).')';
        $valuessql = implode(',', array_fill(0, count($chunk), $valuessql));

        $params = array();
        foreach ($chunk as $dataobject) {
            foreach ($columns as $field => $column) {
                $params[] = $this->normalise_value($column, $dataobject[$field]);
            }
        }

        $sql = "INSERT INTO {$this->prefix}$table $fieldssql VALUES $valuessql";

        list($sql, $params, $type) = $this->fix_sql_params($sql, $params);
        $rawsql = $this->emulate_bound_params($sql, $params);

        $this->query_start($sql, $params, SQL_QUERY_INSERT);
        $result = $this->mysqli->query($rawsql);
        $this->query_end($result);
    }
1003931
public function send(Request $request)
    {
        foreach ($this->cookies as $cookie) {
            $request->addCookie($cookie);
        }

        $response = $this->client->request($request);

        if ($response->getCookies()) {
            $this->cookies = $response->getCookies();
        }

        return $response;
    }
744540
protected function sendRequest(Request $request)
    {
        $curl = curl_init($this->getUrl($request));

        curl_setopt_array($curl, $this->curlOptions);
        curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($request->getRequestFields()));

        $response = curl_exec($curl);

        if(curl_errno($curl))
        {
            $error_message  = 'Error occurred: ' . curl_error($curl);
            $error_code     = curl_errno($curl);
        }
        elseif(curl_getinfo($curl, CURLINFO_HTTP_CODE) != 200)
        {
            $error_code     = curl_getinfo($curl, CURLINFO_HTTP_CODE);
            $error_message  = "Error occurred. HTTP code: '{$error_code}'";
        }

        curl_close($curl);

        if (!empty($error_message))
        {
            throw new RequestException($error_message, $error_code);
        }
        else
        {
            return $response;
        }
    }
243517
protected function response($request, ResponseInterface $response)
    {
        $header = Response::getHeaderOutput($response);
        $headerLength = $length = strlen($header);
        $body = $response->getBody();
        if ($bodySize = $body->getSize() !== null) {
            $length += $bodySize;
        }

        $chunksize = 65520;
        do {
            for ($p = 0; $p + $chunksize < $headerLength; $p += $chunksize) {
                if ($this->sendChunk($request, substr($header, $p, $chunksize)) === false) {
                    $this->log('warning', "send response failed.");
                    break 2;
                }
            }
            $remainder = substr($header, $p);
            try {
                $body->rewind();
                $this->sendChunk($request, $remainder . $body->read($chunksize - strlen($remainder)));
                while (!$body->eof()) {
                    $this->sendChunk($request, $body->read($chunksize));
                }

            } catch (\RuntimeException $e) {
                $this->log('error', $e->getTraceAsString());
                break;
            }

        } while (false);

        $this->endRequest($request, 0, 0);

        return true;
    }
733817
private int sendChunks(ByteBuffer pkt, int maxChunks, OutputStream out) 
                         throws IOException {
    // Sends multiple chunks in one packet with a single write().

    int len = (int) Math.min(endOffset - offset,
                            (((long) bytesPerChecksum) * ((long) maxChunks)));

    // truncate len so that any partial chunks will be sent as a final packet.
    // this is not necessary for correctness, but partial chunks are 
    // ones that may be recomputed and sent via buffer copy, so try to minimize
    // those bytes
    if (len > bytesPerChecksum && len % bytesPerChecksum != 0) {
      len -= len % bytesPerChecksum;
    }

    if (len == 0) {
      return 0;
    }

    int numChunks = (len + bytesPerChecksum - 1)/bytesPerChecksum;
    int packetLen = len + numChunks*checksumSize + 4;
    pkt.clear();

    // The packet format is documented in DFSOuputStream.Packet.getBuffer().
    // Here we need to use the exact packet format since it can be received
    // by both of DFSClient, or BlockReceiver in the case of replication, which
    // uses the same piece of codes as receiving data from DFSOutputStream.
    //

    // write packet header
    pkt.putInt(packetLen);
    if (pktIncludeVersion) {
      pkt.putInt(packetVersion);
    }
    pkt.putLong(offset);
    pkt.putLong(seqno);
    pkt.put((byte)((offset + len >= endOffset) ? 1 : 0));
               //why no ByteBuf.putBoolean()?
    pkt.putInt(len);
    
    int checksumOff = pkt.position();
    byte[] buf = pkt.array();
    
    blockReader.sendChunks(out, buf, offset, checksumOff,
        numChunks, len, crcUpdater, packetVersion);
    
    if (throttler != null) { // rebalancing so throttle
      throttler.throttle(packetLen);
    }
    
    return len;
  }
1374295
def send_chunk(type, content = nil)
      chunk = Chunk.new(type, content).to_s
      socket.write chunk
    end
670082
public function flush(?string $chunk, bool $flushEmpty = false): void
	{
		if($this->isCGI)
		{
			if(!empty($chunk))
			{
				echo $chunk;

				flush();
			}
		}
		else
		{
			if(!empty($chunk) || $flushEmpty === true)
			{
				printf("%x\r\n%s\r\n", strlen($chunk), $chunk);

				flush();
			}
		}
	}
743424
public function send(Request $request)
    {
        $this->logger()->debug('Sending request. {request}', [
            'request'  => $request,
        ]);

        $response = $this->sendOrRetry($request, $request->getRetries());

        $this->logger()->debug('Response received. {response}', [
            'request'  => $request,
            'response' => $response,
        ]);

        return $response;
    }
1234131
async def _send_chunk(self, chunk):
        
        self.__log_debug('> %s', chunk)
        await self.__transport._send_data(serialize_packet(
            self._local_port,
            self._remote_port,
            self._remote_verification_tag,
            chunk))
1023112
private function send(Response $response, Request $request = null): \Generator
    {
        \assert($this->client, "The driver has not been setup; call setup first");

        if ($this->lastWrite) {
            yield $this->lastWrite; // Prevent writing another response until the first is finished.
        }

        $shouldClose = false;

        $protocol = $request !== null ? $request->getProtocolVersion() : "1.0";

        $status = $response->getStatus();
        $reason = $response->getReason();

        $headers = $this->filter($response, $protocol, $request ? $request->getHeaderArray("connection") : []);

        $chunked = !isset($headers["content-length"])
            && $protocol === "1.1"
            && $status >= Status::OK;

        if (!empty($headers["connection"])) {
            foreach ($headers["connection"] as $connection) {
                if (\strcasecmp($connection, "close") === 0) {
                    $chunked = false;
                    $shouldClose = true;
                }
            }
        }

        if ($chunked) {
            $headers["transfer-encoding"] = ["chunked"];
        }

        $buffer = "HTTP/{$protocol} {$status} {$reason}\r\n";
        $buffer .= Rfc7230::formatHeaders($headers);
        $buffer .= "\r\n";

        if ($request !== null && $request->getMethod() === "HEAD") {
            ($this->write)($buffer, $shouldClose);
            return;
        }

        $chunk = ""; // Required for the finally, not directly overwritten, even if your IDE says otherwise.
        $body = $response->getBody();
        $streamThreshold = $this->options->getStreamThreshold();

        try {
            while (null !== $chunk = yield $body->read()) {
                if (!($length = \strlen($chunk))) {
                    continue;
                }

                if ($chunked) {
                    $chunk = \sprintf("%x\r\n%s\r\n", $length, $chunk);
                }

                if (\strlen($buffer) < $streamThreshold) {
                    $buffer .= $chunk;
                    continue;
                }

                // Initially the buffer won't be empty and contains the headers.
                // We save a separate write or the headers here.
                $promise = ($this->write)($buffer);

                $buffer = $chunk;
                $chunk = ""; // Don't use null here, because of the finally

                yield $promise;
            }

            if ($buffer !== "" || $chunked || $shouldClose) {
                yield ($this->write)($chunked ? "{$buffer}0\r\n\r\n" : $buffer, $shouldClose);
            }
        } catch (ClientException $exception) {
            return; // Client will be closed in finally.
        } finally {
            if ($chunk !== null) {
                $this->client->close();
            }
        }
    }
905619
public function addChunk(string $hash, string $chunk, ?string $context = null): bool
    {
        $path = $this->getPath($hash, $context, false);
        if (!file_exists($path)) {
            throw new NotFoundHttpException('temporary file not found');
        }

        $file = fopen($path, "a");
        $result = fwrite($file, $chunk);

        fflush($file);
        fclose($file);

        if ($result === false || $result != strlen($chunk)) {
            return false;
        }

        return true;
    }
481099
public function send(Request $request)
    {
        $ch = curl_init($request->getUrl());
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $request->getMethod());
        curl_setopt($ch, CURLOPT_HTTPHEADER, HttpUtil::formatHeadersForCurl($request->getHeaders()));
        if (!is_null($request->getBody())) {
            curl_setopt($ch, CURLOPT_POSTFIELDS, $request->getBody());
        }

        curl_setopt_array($ch, $request->getCurlOptions());

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FAILONERROR, false);
        curl_setopt($ch, CURLOPT_HEADER, true);

        list($status, $headers, $body) = HttpUtil::parseResponse(curl_exec($ch));

        return new Response(
            HttpUtil::parseStatus($status),
            HttpUtil::parseHeaders($headers),
            $body,
            curl_getinfo($ch)
        );
    }
1178466
private function moveToNextState(CellChunk $chunk)
    {
        $this->state = $chunk->getValueSize() > 0
            ? self::$rowStateEnum['CELL_IN_PROGRESS']
            : self::$rowStateEnum['ROW_IN_PROGRESS'];
    }
46775
public static function canBeUsedForRequest(Request $request)
    {
        $hasChunkParams = $request->has(static::KEY_CHUNK_NUMBER)
                          && $request->has(static::KEY_TOTAL_SIZE)
                          && $request->has(static::KEY_CHUNK_SIZE)
                          && $request->has(static::KEY_CHUNK_CURRENT_SIZE);

        return $hasChunkParams && self::checkChunkParams($request);
    }
1275205
public function send(AbstractRequest $request)
    {
        $handle = HandleFactory::build($request);
        $this->dispatch(MessageEvent::REQUEST, new MessageEvent($request));

        try {
            $result = $handle->execute();
        } catch (\Exception $error) {
            if ($error instanceof CurlException) {
                $response = ResponseFactory::build('', $handle->infos(), $request);
                $error->setResponse($response);
            }
            $this->dispatch(ErrorEvent::ERROR, new ErrorEvent($error));
            throw $error;
        }

        $response = ResponseFactory::build($result, $handle->infos(), $request);
        $this->dispatch(MessageEvent::RESPONSE, new MessageEvent($response));

        return $response;
    }