📄 cms_in.cc
字号:
return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Check to see if there are any unread messages. */ if (queuing_header.queue_length == 0) { return (status = CMS_READ_OLD); } /* Read the header for the message. */ handle_to_global_data->offset += queuing_header.head; if (-1 == handle_to_global_data->read(&header, sizeof(CMS_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 the size of the message. */ if (header.in_buffer_size > max_message_size) { rcs_print_error ("CMS:(%s) Message size of %ld exceeds maximum of %ld\n", BufferName, header.in_buffer_size, max_message_size); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Update the message header. */ header.was_read = 1; if (-1 == handle_to_global_data->write(&header, sizeof(CMS_HEADER))) { rcs_print_error("CMS:(%s) Error writing to global memory at %s:%d\n", BufferName, __FILE__, __LINE__); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Read the message. */ handle_to_global_data->offset += sizeof(CMS_HEADER); if (-1 == handle_to_global_data->read(subdiv_data, (long) header.in_buffer_size)) { rcs_print_error ("CMS:(%s) Error reading from global memory at %s:%d\n", BufferName, __FILE__, __LINE__); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Update the queuing header for the buffer. */ queuing_header.head += header.in_buffer_size + sizeof(CMS_HEADER); if (queuing_header.head >= queuing_header.end_queue_space) { queuing_header.head = sizeof(CMS_QUEUING_HEADER); } queuing_header.queue_length--; if (queuing_header.queue_length == 0) { queuing_header.head = queuing_header.tail = sizeof(CMS_QUEUING_HEADER); queuing_header.end_queue_space = queuing_header.tail; } handle_to_global_data->offset = queuing_header_offset; if (-1 == handle_to_global_data->write(&queuing_header, sizeof(CMS_QUEUING_HEADER))) { rcs_print_error("CMS:(%s) Error writing to global memory at %s:%d\n", BufferName, __FILE__, __LINE__); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Check_id so that debug variables for messages missed can be set. */ check_id(header.write_id); return (status);}/* It takes several steps to perform a read operation on an neutral buffer.*//* 1. Read the encoded header. *//* 2. Decode the header. *//* 3. Check the id and size. *//* 4. If id and size are ok, then read the message and update the header. */CMS_STATUS CMS::read_encoded(){ /* Produce error message if process does not have permission to read. */ if (!read_permission_flag) { rcs_print_error("CMS: %s was not configured to read %s\n", ProcessName, BufferName); return (status = CMS_PERMISSIONS_ERROR); } /* 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); } /* Read the encoded header for the message. */ 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 header structure. */ decode_header(); /* Determine if the message in the buffer is new to this process. */ if (check_id(header.write_id) == CMS_READ_OK) { /* Check the size of the message. */ if (header.in_buffer_size > max_message_size) { rcs_print_error ("CMS:(%s) Message size of %ld exceeds maximum of %ld\n", BufferName, header.in_buffer_size, max_message_size); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Read the message. */ handle_to_global_data->offset += encoded_header_size; if (-1 == handle_to_global_data->read(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); } handle_to_global_data->offset -= encoded_header_size; } /* Update the header. */ header.was_read = 1; 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); } return (status);}/* It takes several steps to perform a read operation */ /* when queuing is enabled on a neutral buffer. *//* 1. Read the encoded queuing_header at the beginning of the buffer. *//* 2. Decode the queuing_header for the buffer. *//* 3. Get the head of the queue from the queuing_header. *//* 4. Read the message header at the head of the queue. *//* 5. Decode the message header. *//* 6. Check the id and size. *//* 7. If id and size are ok, */ /* then read the message */CMS_STATUS CMS::queue_read_encoded(){ long queuing_header_offset; /* Produce error message if process does not have permission to read. */ if (!read_permission_flag) { rcs_print_error("CMS: %s was not configured to read %s\n", ProcessName, BufferName); return (status = CMS_PERMISSIONS_ERROR); } /* Check that the handle to global memory 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 encoded header for 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 the queuing header and store in the queuing_header structrure. */ decode_queuing_header(); /* Determine if there are any unread messages. */ if (queuing_header.queue_length == 0) { return (status = CMS_READ_OLD); } /* Read the header for the message. */ handle_to_global_data->offset += queuing_header.head; 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__); 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); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Decode the message header and store in the header structure. */ decode_header(); /* Check the size of the message. */ if (header.in_buffer_size > max_message_size) { rcs_print_error ("CMS:(%s) Message size of %ld exceeds maximum of %ld\n", BufferName, header.in_buffer_size, max_message_size); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Update the message header. */ header.was_read = 1; 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__); 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); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Read the message. */ handle_to_global_data->offset += encoded_header_size; if (-1 == handle_to_global_data->read(encoded_data, (long) header.in_buffer_size)) { rcs_print_error ("CMS:(%s) Error reading from global memory at %s:%d\n", BufferName, __FILE__, __LINE__); 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); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Update the buffer header. */ queuing_header.head += header.in_buffer_size + encoded_header_size; if (queuing_header.head >= queuing_header.end_queue_space) { queuing_header.head = encoded_queuing_header_size; } queuing_header.queue_length--; if (queuing_header.queue_length == 0) { queuing_header.head = queuing_header.tail = encoded_queuing_header_size; queuing_header.end_queue_space = queuing_header.tail; } encode_queuing_header(); handle_to_global_data->offset = queuing_header_offset; 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__); 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); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Check_id so that debug variables for messages missed can be set. */ check_id(header.write_id); return (status);}/***************************************************************** Peek operations are the same as reads, except that the header(s) are not updated.****************************************************************//* It takes several steps to perform a peek operation. *//* 1. Read the header. *//* 2. Check the id and size. *//* 3. If id and size are ok, then read the message. */CMS_STATUS CMS::peek_raw(){ /* Produce error message if process does not have permission to read. */ if (!read_permission_flag) { rcs_print_error("CMS: %s was not configured to read %s\n", ProcessName, BufferName); return (status = CMS_PERMISSIONS_ERROR); } /* Check that the handle to global memory exists. */ if (NULL == handle_to_global_data) { rcs_print_error("CMS:(%s) handle_to_global_data is NULL.\n", BufferName); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Read the header for the message. */ if (-1 == handle_to_global_data->read(&header, sizeof(CMS_HEADER))) { rcs_print_error ("CMS:(%s) Error reading from global memory at %s:%d\n", BufferName, __FILE__, __LINE__); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Set status to CMS_READ_OLD or CMS_READ_OK */ if (check_id(header.write_id) == CMS_READ_OLD) { return (status); /* Don't bother copying out an old message. */ } /* Check the size of the message. */ if (header.in_buffer_size > max_message_size) { rcs_print_error ("CMS:(%s) Message size of %ld exceeds maximum of %ld\n", BufferName, header.in_buffer_size, max_message_size); return (status = CMS_INTERNAL_ACCESS_ERROR); } /* Read the message. */ handle_to_global_data->offset += sizeof(CMS_HEADER); if (-1 == handle_to_global_data->read(subdiv_data, (long) header.in_buffer_size)) { rcs_print_error ("CMS:(%s) Error reading from global memory at %s:%d\n", BufferName, __FILE__, __LINE__); return (status = CMS_INTERNAL_ACCESS_ERROR); } return (status);}/* It takes several steps to perform a peek operation when queuing is enabled. *//* 1. Read the queuing_header at the beginning of the buffer. *//* 2. Get the head of the queue from the queuing_header. *//* 3. Read the message header at the head of the queue. *//* 4. Check the id and size. *//* 5. If id and size are ok, */ /* then read the message */CMS_STATUS CMS::queue_peek_raw(){ long queuing_header_offset; /* Produce error message if process does not have permission to read. */ if (!read_permission_flag) { rcs_print_error("CMS: %s was not configured to read %s\n", ProcessName, BufferName); return (status = CMS_PERMISSIONS_ERROR); } /* Check that the handle to global memory 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 that we can update the header later. */ queuing_header_offset = handle_to_global_data->offset; /* Read the queuing header for 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 to see if there are any unread messages. */ if (queuing_header.queue_length == 0) { return (status = CMS_READ_OLD); } /* Read the header for the message. */ handle_to_global_data->offset += queuing_header.head; if (-1 == handle_to_global_data->read(&header, sizeof(CMS_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 the size of the message. */ if (header.in_buffer_size > max_message_size) { rcs_print_error ("CMS:(%s) Message size of %ld exceeds maximum of %ld\n", BufferName, header.in_buffer_size, max_message_size); return (status = CMS_INTERNAL_ACCESS_ERROR); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -