📄 cms_in.cc
字号:
/* Store the header information to use after reading the header in the buffer. */ current_header = header; /* Check that handle to global memory object exists. */ if (NULL == handle_to_global_data) { rcs_print_error("CMS: handle_to_global_data is NULL.\n"); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Check that buffer is large enough for this message. */ if (header.in_buffer_size > max_message_size) { rcs_print_error ("CMS:(%s) Message size %ld exceeds maximum for this buffer of %ld.\n", BufferName, header.in_buffer_size, max_message_size); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Read the header. */ if (-1 == handle_to_global_data->read(encoded_header, encoded_header_size)) { rcs_print_error ("CMS:(%s) Error reading from global memory at %s:%d\n", BufferName, __FILE__, __LINE__); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Decode the header and store in the header structure. */ decode_header(); /* Update the header. */ header.was_read = 0; header.write_id++; if (split_buffer && (header.write_id % 2) != toggle_bit) { header.write_id++; } header.in_buffer_size = current_header.in_buffer_size; encode_header(); if (-1 == handle_to_global_data->write(encoded_header, encoded_header_size)) { rcs_print_error("CMS:(%s) Error writing to global memory at %s:%d\n", BufferName, __FILE__, __LINE__); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Write the message. */ handle_to_global_data->offset += encoded_header_size; if (-1 == handle_to_global_data->write(encoded_data, (long) header.in_buffer_size)) { rcs_print_error("CMS:(%s) Error writing to global memory at %s:%d\n", BufferName, __FILE__, __LINE__); return (status = CMS_INTERNAL_ACCESS_ERROR); } return (status = CMS_WRITE_OK);}/* It takes several steps to perform a write operation when queuing is enabled. *//* 1. Read the qeuing header at the begining of the buffer. *//* 2. Determine the amount of free space and where the next node can be placed.*//* 3. Set up message header from info in the queuing header. *//* 4. Write the message header and message at the tail of the queue. *//* 5. Update the queuing header. *//* Parameters: */ /* user_data - pointer to where the user stored the message to be written. */CMS_STATUS CMS::queue_write_encoded(){ CMS_HEADER current_header; long queuing_header_offset; long original_tail; /* Produce error message if process does not have permission to read. */ if (!write_permission_flag) { rcs_print_error("CMS: %s was not configured to write to %s\n", ProcessName, BufferName); return (status = CMS_PERMISSIONS_ERROR); } /* Store the header information to use after reading the header in the buffer. */ current_header = header; /* Check that the handle to the global memory object exists. */ if (NULL == handle_to_global_data) { rcs_print_error("CMS: handle_to_global_data is NULL.\n"); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Store the original offset so we can update the queuing header later. */ queuing_header_offset = handle_to_global_data->offset; /* Read the queuing header at the beginning of the buffer. */ if (-1 == handle_to_global_data->read(encoded_queuing_header, encoded_queuing_header_size)) { rcs_print_error ("CMS:(%s) Error reading from global memory at %s:%d\n", BufferName, __FILE__, __LINE__); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Decode queuing header and store in queuing_header structure. */ decode_queuing_header(); /* Determine amount of free space and location of next node. */ if (handle_to_global_data->size - queuing_header.tail - queuing_header_offset > header.in_buffer_size + encoded_header_size && queuing_header.tail > queuing_header.head) { free_space = handle_to_global_data->size - queuing_header.tail - queuing_header_offset; } else if (queuing_header.tail < queuing_header.head) { free_space = queuing_header.head - queuing_header.tail; } else if (queuing_header.head > encoded_header_size + queuing_header_offset + header.in_buffer_size + encoded_queuing_header_size) { queuing_header.end_queue_space = queuing_header.tail; queuing_header.tail = encoded_queuing_header_size; free_space = queuing_header.head - encoded_queuing_header_size - queuing_header_offset; } else { free_space = 0; } if (queuing_header.queue_length == 0) { queuing_header.head = queuing_header.tail = encoded_queuing_header_size; queuing_header.queue_length = 0; queuing_header.end_queue_space = queuing_header.tail; free_space = handle_to_global_data->size - encoded_queuing_header_size - queuing_header_offset; } if (cms_print_queue_free_space) { rcs_print("queue free space = %d\n", free_space); rcs_print(" { head=%d,tail=%d,end=%d,length=%d,id=%d }\n", queuing_header.head, queuing_header.tail, queuing_header.end_queue_space, queuing_header.queue_length, queuing_header.write_id); } /* Check to see if there is enough free space. */ if (free_space < header.in_buffer_size + encoded_header_size) { if (cms_print_queue_free_space || cms_print_queue_full_messages) { rcs_print_error("CMS: %s message queue is full.\n", BufferName); rcs_print_error ("(continued) CMS: Message requires %ld bytes but only %ld bytes are left.\n", header.in_buffer_size, free_space); } return (status = CMS_QUEUE_FULL); } /* Store original tail so we'll know where to store the message. */ original_tail = queuing_header.tail; /* Update the queuing header. */ queuing_header.tail += header.in_buffer_size + encoded_header_size; queuing_header.queue_length++; queuing_header.write_id++; if (queuing_header.end_queue_space < queuing_header.tail) { queuing_header.end_queue_space = queuing_header.tail; } encode_queuing_header(); if (-1 == handle_to_global_data->write(encoded_queuing_header, encoded_queuing_header_size)) { rcs_print_error("CMS:(%s) Error writing to global memory at %s:%d\n", BufferName, __FILE__, __LINE__); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Setup message header. */ header.write_id = queuing_header.write_id; header.was_read = 0; header.in_buffer_size = current_header.in_buffer_size; /* Re-encode the header. */ encode_header(); /* Write the message header. */ handle_to_global_data->offset += original_tail; if (-1 == handle_to_global_data->write(encoded_header, encoded_header_size)) { rcs_print_error("CMS:(%s) Error writing to global memory at %s:%d\n", BufferName, __FILE__, __LINE__); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Write the message. */ handle_to_global_data->offset += encoded_header_size; if (-1 == handle_to_global_data->write(encoded_data, (long) header.in_buffer_size)) { rcs_print_error("CMS:(%s) Error writing to global memory at %s:%d\n", BufferName, __FILE__, __LINE__); return (status = CMS_INTERNAL_ACCESS_ERROR); } return (status = CMS_WRITE_OK);}/* It takes several steps to perform a write operation. *//* 1. Read the header. *//* 2. Update the header. *//* 3. Write the message. *//* Parameters: */ /* user_data - pointer to where the user stored the message to be written. */CMS_STATUS CMS::write_if_read_raw(void *user_data){ CMS_HEADER current_header; /* Produce error message if process does not have permission to read. */ if (!write_permission_flag) { rcs_print_error("CMS: %s was not configured to write to %s\n", ProcessName, BufferName); return (status = CMS_PERMISSIONS_ERROR); } /* Store the header information to use after reading the header in the buffer. */ current_header = header; /* Check that handle to global memory object exists. */ if (NULL == handle_to_global_data) { rcs_print_error("CMS: handle_to_global_data is NULL.\n"); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Check that buffer is large enough for this message. */ if (header.in_buffer_size > max_message_size) { rcs_print_error ("CMS:(%s) Message size %ld exceeds maximum for this buffer of %ld.\n", BufferName, header.in_buffer_size, max_message_size); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Read the header. */ if (-1 == handle_to_global_data->read(&header, sizeof(header))) { rcs_print_error ("CMS:(%s) Error reading from global memory at %s:%d\n", BufferName, __FILE__, __LINE__); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Check if the message in the buffer has been read. */ if (!header.was_read) { return (status = CMS_WRITE_WAS_BLOCKED); } /* Update the header. */ header.was_read = 0; header.write_id++; if (split_buffer && (header.write_id % 2) != toggle_bit) { header.write_id++; } header.in_buffer_size = current_header.in_buffer_size; if (-1 == handle_to_global_data->write(&header, sizeof(header))) { rcs_print_error("CMS:(%s) Error writing to global memory at %s:%d\n", BufferName, __FILE__, __LINE__); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Write the message. */ handle_to_global_data->offset += sizeof(CMS_HEADER); if (-1 == handle_to_global_data->write(user_data, (long) header.in_buffer_size)) { rcs_print_error("CMS:(%s) Error writing to global memory at %s:%d\n", BufferName, __FILE__, __LINE__); return (status = CMS_INTERNAL_ACCESS_ERROR); } return (status = CMS_WRITE_OK);}/* It takes several steps to perform a write operation when queuing is enabled. *//* 1. Read the qeuing header at the begining of the buffer. *//* 2. Determine the amount of free space and where the next node can be placed.*//* 3. Set up message header from info in the queuing header. *//* 4. Write the message header and message at the tail of the queue. *//* 5. Update the queuing header. *//* Parameters: */ /* user_data - pointer to where the user stored the message to be written. */CMS_STATUS CMS::queue_write_if_read_raw(void *user_data){ CMS_HEADER current_header; long queuing_header_offset; long original_tail; /* Produce error message if process does not have permission to read. */ if (!write_permission_flag) { rcs_print_error("CMS: %s was not configured to write to %s\n", ProcessName, BufferName); return (status = CMS_PERMISSIONS_ERROR); } /* Store the header information to use after reading the header in the buffer. */ current_header = header; /* Check that the handle to the global memory object exists. */ if (NULL == handle_to_global_data) { rcs_print_error("CMS: handle_to_global_data is NULL.\n"); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Store the original offset so we can update the queuing header later. */ queuing_header_offset = handle_to_global_data->offset; /* Read the queuing header at the beginning of the buffer. */ if (-1 == handle_to_global_data->read(&queuing_header, sizeof(CMS_QUEUING_HEADER))) { rcs_print_error ("CMS:(%s) Error reading from global memory at %s:%d\n", BufferName, __FILE__, __LINE__); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Check if all the messages in the buffer have been read. */ if (0 != queuing_header.queue_length) { return (status = CMS_WRITE_WAS_BLOCKED); } /* Determine amount of free space and location of next node. */ if (handle_to_global_data->size - queuing_header.tail - queuing_header_offset > ((long) (header.in_buffer_size + sizeof(CMS_HEADER))) && queuing_header.tail > queuing_header.head) { free_space = handle_to_global_data->size - queuing_header.tail - queuing_header_offset; } else if (queuing_header.tail < queuing_header.head) { free_space = queuing_header.head - queuing_header.tail; } else if (queuing_header.head > ((long) (queuing_header_offset + sizeof(CMS_QUEUING_HEADER) + header.in_buffer_size + sizeof(CMS_HEADER)))) { queuing_header.end_queue_space = queuing_header.tail; queuing_header.tail = sizeof(CMS_QUEUING_HEADER); free_space = queuing_header.head - sizeof(CMS_QUEUING_HEADER) - queuing_header_offset; } else { free_space = 0; } if (queuing_header.queue_length == 0) { queuing_header.head = queuing_header.tail = sizeof(CMS_QUEUING_HEADER); queuing_header.queue_length = 0; queuing_header.end_queue_space = queuing_header.tail; free_space = handle_to_global_data->size - sizeof(CMS_QUEUING_HEADER) - queuing_header_offset; } if (cms_print_queue_free_space) { rcs_print("queue free space = %d\n", free_space); rcs_print(" { head=%d,tail=%d,end=%d,length=%d,id=%d }\n", queuing_header.head, queuing_header.tail, queuing_header.end_queue_space, queuing_header.queue_length, queuing_header.write_id); } /* Check to see if there is enough free space. */ if (free_space < ((long) (header.in_buffer_size + sizeof(CMS_HEADER)))) { if (cms_print_queue_free_space || cms_print_queue_full_messages) { rcs_print_error("CMS: %s message queue is full.\n", BufferName); rcs_print_error ("(continued) CMS: Message requires %ld bytes but only %ld bytes are left.\n", header.in_buffer_size, free_space); } return (status = CMS_QUEUE_FULL); } /* Store original tail so we'll know where to store the message. */ original_tail = queuing_header.tail; /* Update the queuing header. */ queuing_header.tail += header.in_buffer_size + sizeof(CMS_HEADER); queuing_header.queue_length++; queuing_header.write_id++; if (queuing_header.end_queue_space < queuing_header.tail) { queuing_header.end_queue_space = queuing_header.tail; } if (-1 == handle_to_global_data->write(&queuing_header, sizeof(CMS_QUEUING_HEADER))) { rcs_print_error("CMS:(%s)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -