Ejemplo n.º 1
0
void read_state_file (void) {
  if (binlog_enabled) { return; }
  int state_file_fd = open (get_state_filename (), O_CREAT | O_RDWR, 0600);
  if (state_file_fd < 0) {
    return;
  }
  int version, magic;
  if (read (state_file_fd, &magic, 4) < 4) { close (state_file_fd); return; }
  if (magic != (int)STATE_FILE_MAGIC) { close (state_file_fd); return; }
  if (read (state_file_fd, &version, 4) < 4) { close (state_file_fd); return; }
  assert (version >= 0);
  int x[4];
  if (read (state_file_fd, x, 16) < 16) {
    close (state_file_fd); 
    return;
  }
  int pts = x[0];
  int qts = x[1];
  int seq = x[2];
  int date = x[3];
  close (state_file_fd); 
  bl_do_set_seq (TLS, seq);
  bl_do_set_pts (TLS, pts);
  bl_do_set_qts (TLS, qts);
  bl_do_set_date (TLS, date);
}
Ejemplo n.º 2
0
void read_state_file(struct tgl_state *TLS) {
	CMStringA name(FORMAT, "%sstate", TLS->base_path);
	int state_file_fd = open(name, O_CREAT | O_RDWR | O_BINARY, 0600);

	if (state_file_fd < 0) {
		return;
	}
	int version, magic;
	if (read(state_file_fd, &magic, 4) < 4) { close(state_file_fd); return; }
	if (magic != (int)STATE_FILE_MAGIC) { close(state_file_fd); return; }
	if (read(state_file_fd, &version, 4) < 4 || version < 0) { close(state_file_fd); return; }
	int x[4];
	if (read(state_file_fd, x, 16) < 16) {
		close(state_file_fd);
		return;
	}
	int pts = x[0];
	int qts = x[1];
	int seq = x[2];
	int date = x[3];
	close(state_file_fd);
	bl_do_set_seq(TLS, seq);
	bl_do_set_pts(TLS, pts);
	bl_do_set_qts(TLS, qts);
	bl_do_set_date(TLS, date);
	TLS->callback.logprintf("read state file: seq=%d pts=%d qts=%d date=%d", seq, pts, qts, date);
}
Ejemplo n.º 3
0
void CTelegramProto::ReadState()
{
	DBVARIANT dbv = { 0 };
	if (db_get(0, m_szModuleName, "TGL_STATE", &dbv))
		return;

	int *x = (int*)dbv.pbVal;

	bl_do_set_seq(TLS, x[0]);
	bl_do_set_pts(TLS, x[1]);
	bl_do_set_qts(TLS, x[2]);
	bl_do_set_date(TLS, x[3]);

	db_free(&dbv);
}