Exemple #1
0
static void prepare_write_cb(guint8 status, const guint8 *rpdu,
					guint16 rlen, gpointer user_data)
{
	struct write_long_data *long_write = user_data;

	if (status != 0) {
		long_write->func(status, rpdu, rlen, long_write->user_data);
		return;
	}

	/* Skip Prepare Write Response PDU header (5 bytes) */
	long_write->offset += rlen - 5;

	if (long_write->offset == long_write->vlen){
		execute_write(long_write->attrib, ATT_WRITE_ALL_PREP_WRITES,
				long_write->func, long_write->user_data);
		g_free(long_write->value);
		g_free(long_write);

		return;
	}

	prepare_write(long_write->attrib, long_write->handle,
		long_write->offset, long_write->value, long_write->vlen,
		long_write->func, long_write);
}
Exemple #2
0
static int
emit_set (workerState * ws)
{
  simpleBuf *sb;
  char *bp, *cp;
  int nr, i;
  static const char *data10 = "0123456789";

  sb = &ws->out;


  sb_reserve (sb, 128 + ws->size);
  cp = sb->cp;
  nr = sprintf (cp, "SET %d ", ws->key);
  assert (nr > 0);
  cp += nr;
  bp = cp;
  for (i = 0; i < ws->size; i++)
    {
      int idx = rand () % 10;
      *cp++ = data10[idx];
    }
  ks_crc_next[ws->key] = crc16 (bp, cp - bp, ks_crc[ws->key]);
  *cp++ = '\r';
  *cp++ = '\n';
  sb->ep = cp;
  ws->num_rqst++;

  return prepare_write (ws);
}
void *write_alloc (int s) {
  char *p;
  int t = (s + 3) & -4;
  assert (s > 0 && s <= WRITE_THRESHOLD);
  prepare_write (t);
  p = wptr;
  wptr += t;
  while (s < t) {
    p[s++] = LEV_ALIGN_FILL;
  }
  return p;
}
Exemple #4
0
static VALUE my_write(VALUE io, VALUE str, int io_wait)
{
	struct io_args a;
	long n;

	prepare_write(&a, io, str);
	set_nonblocking(a.fd);
retry:
	n = (long)write(a.fd, a.ptr, a.len);
	if (write_check(&a, n, "write", io_wait) != 0)
		goto retry;
	return a.buf;
}
Exemple #5
0
/*
 * This method behaves like Kgio::PipeMethods#kgio_write, except
 * it will use send(2) with the MSG_DONTWAIT flag on sockets to
 * avoid unnecessary calls to fcntl(2).
 */
static VALUE my_send(VALUE io, VALUE str, int io_wait)
{
	struct io_args a;
	long n;

	prepare_write(&a, io, str);
retry:
	n = (long)send(a.fd, a.ptr, a.len, MSG_DONTWAIT);
	if (write_check(&a, n, "send", io_wait) != 0)
		goto retry;
	if (TYPE(a.buf) != T_SYMBOL)
		kgio_autopush_send(io);
	return a.buf;
}
Exemple #6
0
static void write_to_file(log_t l,int32_t is_close)
{
	mutex_lock(l->mtx);
	if(!list_is_empty(l->log_queue))
		link_list_swap(l->pending_log,l->log_queue);
	mutex_unlock(l->mtx);
	if(is_close)
	{
		//日志系统关闭,写入关闭消息
		char buf[4096];
		time_t t = time(NULL);
		struct tm re;
		struct tm *_tm = localtime_r(&t,&re);
		snprintf(buf,4096,"[%d-%d-%d %d:%d:%d]close log sucessful\n",_tm->tm_year+1900,_tm->tm_mon+1,_tm->tm_mday,_tm->tm_hour,_tm->tm_min,_tm->tm_sec);
		int32_t str_len = strlen(buf);
		wpacket_t w = wpacket_create(0,NULL,str_len,1);
		wpacket_write_binary(w,buf,str_len);	
		LINK_LIST_PUSH_BACK(l->pending_log,w);
	}
	while(!list_is_empty(l->pending_log))
	{
		int32_t wbuf_count = prepare_write(l);
		int32_t bytetransfer = TEMP_FAILURE_RETRY(writev(l->file_descriptor,l->wbuf,wbuf_count));
		if(bytetransfer > 0)
		{
			l->file_size += bytetransfer;
			on_write_finish(l,bytetransfer);
			g_log_system->bytes += bytetransfer;
		}
		if(bytetransfer <= 0)
		{
			printf("errno: %d wbuf_count: %d\n",errno,wbuf_count);
		}
		if(last_tick +1000 <= GetSystemMs())
		{
			printf("log/ms:%u\n",log_count);
			last_tick = GetSystemMs();
			log_count = 0;
		}
	}
	
	if(!is_close)
	{
		/*
		* if(l->file_size > max_log_filse_size)
		* 文件超过一定大小,将原文件重命名,开一个新的文件
		*/
	}
}
Exemple #7
0
static int
emit_get (workerState * ws)
{
  int nr;
  simpleBuf *sb;

  assert (ws->key >= 0);
  sb = &ws->out;
  assert (sb->cp == sb->buf);

  sb_reserve (sb, 128);
  nr = sprintf (sb->cp, "GET %d\r\n", ws->key);
  assert (nr > 0 && nr < 128);
  sb->ep = sb->buf + nr;

  return prepare_write (ws);;
}
Exemple #8
0
/*
 * call-seq:
 *
 *	io.kgio_syssend(str, flags) -> nil, String or :wait_writable
 *
 * Returns nil if the write was completed in full.
 *
 * Returns a String containing the unwritten portion if EAGAIN
 * was encountered, but some portion was successfully written.
 *
 * Returns :wait_writable if EAGAIN is encountered and nothing
 * was written.
 *
 * This method is only available on Ruby 1.9.3 or later.
 */
static VALUE kgio_syssend(VALUE io, VALUE str, VALUE flags)
{
	struct wr_args a;
	long n;

	a.flags = NUM2INT(flags);
	prepare_write(&a, io, str);
	if (a.flags & MY_MSG_DONTWAIT) {
		do {
			n = (long)send(a.fd, a.ptr, a.len, a.flags);
		} while (write_check(&a, n, "send", 0) != 0);
	} else {
		do {
			n = (long)rb_thread_io_blocking_region(
						nogvl_send, &a, a.fd);
		} while (write_check(&a, n, "send", 0) != 0);
	}
	return a.buf;
}
Exemple #9
0
int git_object_write(git_object *object)
{
	int error;
	git_odb_source *source;

	assert(object);

	if (object->modified == 0)
		return GIT_SUCCESS;

	prepare_write(object);
	source = &object->source;

	switch (source->raw.type) {
	case GIT_OBJ_COMMIT:
		error = git_commit__writeback((git_commit *)object, source);
		break;

	case GIT_OBJ_TREE:
		error = git_tree__writeback((git_tree *)object, source);
		break;

	case GIT_OBJ_TAG:
		error = git_tag__writeback((git_tag *)object, source);
		break;

	case GIT_OBJ_BLOB:
		error = git_blob__writeback((git_blob *)object, source);
		break;

	default:
		error = GIT_ERROR;
		break;
	}

	if (error < GIT_SUCCESS) {
		git_object__source_close(object);
		return error;
	}

	return write_back(object);
}
Exemple #10
0
guint gatt_write_char(GAttrib *attrib, uint16_t handle, uint8_t *value,
			size_t vlen, GAttribResultFunc func, gpointer user_data)
{
	uint8_t *buf;
	size_t buflen;
	guint16 plen;
	struct write_long_data *long_write;

	buf = g_attrib_get_buffer(attrib, &buflen);

	/* Only use Write Request/Command if payload fits on a single transfer,
	 * including 3 bytes for the header. */
	if (vlen <= buflen - 3) {
		if (func)
			plen = enc_write_req(handle, value, vlen, buf,
								buflen);
		else
			plen = enc_write_cmd(handle, value, vlen, buf,
								buflen);

		return g_attrib_send(attrib, 0, buf, plen, func,
							user_data, NULL);
	}

	/* Write Long Characteristic Values */
	long_write = g_try_new0(struct write_long_data, 1);
	if (long_write == NULL)
		return 0;

	long_write->attrib = attrib;
	long_write->func = func;
	long_write->user_data = user_data;
	long_write->handle = handle;
	long_write->value = g_memdup(value, vlen);
	long_write->vlen = vlen;

	return prepare_write(attrib, handle, long_write->offset, value, vlen,
							func, long_write);
}
Exemple #11
0
_PUBLIC_ size_t fwrite(const void *ptr, size_t size, size_t nmemb,
                       FILE *stream) {
  prepare_write(ptr, size * nmemb);
  return WRAP(fwrite)(ptr, size, nmemb, stream);
}
Exemple #12
0
_PUBLIC_ ssize_t write(int fd, const void *buf, size_t count) {
  prepare_write(buf, count);
  return WRAP(write)(fd, buf, count);
}