コード例 #1
0
ファイル: test_writeread.c プロジェクト: LLNL/cruise
/* write the checkpoint data to fd, and return whether the write was successful */
int write_checkpoint(int fd, int rank, int ckpt, char* buf, size_t size)
{
  int rc;
  int valid = 0;
  char rank_buf[7];
  char ckpt_buf[7];
  size_t field_size = 6;

  /* write the rank id */
  sprintf(rank_buf, "%06d", rank);
  rc = reliable_write(fd, rank_buf, field_size);
  if (rc < 0) {
    valid = 0;
  }

  /* write the checkpoint id (application timestep) */
  sprintf(ckpt_buf, "%06d", ckpt);
  rc = reliable_write(fd, ckpt_buf, field_size);
  if (rc < 0) {
    valid = 0;
  }

  /* write the checkpoint data */
  rc = reliable_write(fd, buf, size);
  if (rc < 0) {
    valid = 0;
  }

  return valid;
}
コード例 #2
0
ファイル: packet.c プロジェクト: charles-dyfis-net/ccgfs
/**
 * pkt_send - send packet and destroy
 * @fd:		file descriptor to write it to
 * @pkt:	packet structure
 *
 * Writes the packet length into the actual transmission buffer, sends the
 * packet out to @fd and then destroys it.
 */
void pkt_send(int fd, struct lo_packet *pkt)
{
	struct ccgfs_pkt_header *hdr = pkt->data;
	hdr->length = cpu_to_le32(pkt->length);
	reliable_write(fd, hdr, pkt->length);
	__pkt_destroy(pkt);
}
コード例 #3
0
ファイル: demultiplex.c プロジェクト: ryanolson/Spindle
int demultiplex_write(void *session, int fd, int id, const void *buf, size_t size)
{
   int result;
   msg_header_t msg_header;
   int write_lock_held = 0;
   int error_return = -1;

   msg_header.msg_size = size;
   msg_header.msg_target = id;

   result = take_write_lock(session);
   if (result == -1)
      goto error;
   write_lock_held = 1;

   result = reliable_write(fd, &msg_header, sizeof(msg_header));
   if (result == -1) {
      set_last_error("Error writing header from client to server");
      goto error;
   }
   if (result == 0) 
      goto eof_error;

   result = reliable_write(fd, buf, size);
   if (result == -1) {
      set_last_error("Error writing message from client to server");
      goto error;
   }
   if (result == 0) 
      goto eof_error;

   result = release_write_lock(session);
   if (result == -1)
      goto error;
   write_lock_held = 0;

   return size;

  eof_error:
   error_return = 0;
  error:
   if (write_lock_held)
      release_write_lock(session);

   return error_return;
}
コード例 #4
0
 /**
  * Writes the given number of bytes from the output_buffer to the file descriptor.
  * This is just a wrapper around write(2), because write(2) can write less than
  * the given number of bytes.
  *
  * @param fd File descriptor.
  * @param output_buffer Buffer with data to be written. Must be at least size bytes long.
  * @param size Number of bytes to write.
  * @throws std::system_error On error.
  */
 inline void reliable_write(const int fd, const char* output_buffer, const size_t size) {
     reliable_write(fd, reinterpret_cast<const unsigned char*>(output_buffer), size);
 }