예제 #1
0
파일: server.c 프로젝트: SongJLG/johan-doc
static bool
send_chunk(Request* request)
{
  Py_ssize_t bytes_sent;
  static uv_buf_t resbuf;
  uv_write_t * wr;
  wr = (uv_buf_t*) malloc(sizeof *wr);
  //dprint("发送chunk:\n%s",PyString_AS_STRING(request->current_chunk) + request->current_chunk_p);
  dprint("发送大小:%d",PyString_GET_SIZE(request->current_chunk) - request->current_chunk_p);
  assert(request->current_chunk != NULL);
  assert(!(request->current_chunk_p == PyString_GET_SIZE(request->current_chunk)
         && PyString_GET_SIZE(request->current_chunk) != 0));
  resbuf = uv_buf_init(PyString_AS_STRING(request->current_chunk) + request->current_chunk_p, PyString_GET_SIZE(request->current_chunk) - request->current_chunk_p);
  bytes_sent = uv_write(
		   wr,
		   request->ev_watcher,
		   &resbuf,
		   1,
		   after_write);

  if(bytes_sent == -1){
    dprint("发送数据出错");
	dprint("chunk:\n%s",PyString_AS_STRING(request->current_chunk) + request->current_chunk_p);
    return handle_nonzero_errno(request);
  }
  request->current_chunk_p += resbuf.len;
  if(request->current_chunk_p == PyString_GET_SIZE(request->current_chunk)) {
    Py_CLEAR(request->current_chunk);
    request->current_chunk_p = 0;
    return false;
  }
  //@@@@@@@@@@@@@@@@@ Py_CLEAR(request->current_chunk);
  //@@@@@@@@@@@@@@@@@ free(resbuf.base);
  return true;
}
예제 #2
0
파일: server.c 프로젝트: liveck/bjoern
static bool
send_chunk(Request* request)
{
  Py_ssize_t bytes_sent;

  assert(request->current_chunk != NULL);
  assert(!(request->current_chunk_p == PyString_GET_SIZE(request->current_chunk)
         && PyString_GET_SIZE(request->current_chunk) != 0));

  bytes_sent = write(
    request->client_fd,
    PyString_AS_STRING(request->current_chunk) + request->current_chunk_p,
    PyString_GET_SIZE(request->current_chunk) - request->current_chunk_p
  );

  if(bytes_sent == -1)
    return handle_nonzero_errno(request);

  request->current_chunk_p += bytes_sent;
  if(request->current_chunk_p == PyString_GET_SIZE(request->current_chunk)) {
    Py_CLEAR(request->current_chunk);
    request->current_chunk_p = 0;
    return false;
  }
  return true;
}
예제 #3
0
파일: server.c 프로젝트: liveck/bjoern
static bool
do_sendfile(Request* request)
{
  Py_ssize_t bytes_sent = portable_sendfile(
      request->client_fd,
      request->current_chunk_p /* current_chunk_p stores the file fd */
  );
  if(bytes_sent == -1)
    return handle_nonzero_errno(request);
  return bytes_sent != 0;
}
예제 #4
0
파일: server.c 프로젝트: geekbuntu/bjoern
static bool
do_sendfile(Request* request)
{
  Py_ssize_t bytes_sent = sendfile(
    request->client_fd,
    request->current_chunk_p, /* current_chunk_p stores the file fd */
    NULL, SENDFILE_CHUNK_SIZE
  );
  if(bytes_sent == -1)
    return handle_nonzero_errno(request);
  return bytes_sent != 0;
}