本文整理汇总了C++中receive_message函数的典型用法代码示例。如果您正苦于以下问题:C++ receive_message函数的具体用法?C++ receive_message怎么用?C++ receive_message使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了receive_message函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: procA
void procA ()
{
//receive the message envelope from CCI when user types in 's'
//then deallocate the received message envelope
ps("1");
MsgEnv *init_msg = (MsgEnv*)receive_message();
while (init_msg==NULL) {
init_msg = (MsgEnv*)receive_message();
}
release_message_env(init_msg);
ps("2");
//initialize counter
int num_count = 0;
//loop forever
while(1)
{
//request a message envelope, and set the type to COUNT_REPORT
//set the data field of the msg env equal to the counter
MsgEnv *toB = (MsgEnv*)request_msg_env();
toB->msg_type = COUNT_REPORT;
toB->data[0] = (char)num_count;
toB->data[1] = '\0';
//send the message envelope to B
//increment the counter and yield the processor to other processes
send_message(PROCB_ID, toB);
num_count++;
ps("test2");
release_processor();
}
}
示例2: proc2
//Test 1 reciever (message can be accurately sent/recieved)
void proc2(void) {
int pid = 2;
int sender = 1;
msgbuf *msg;
msg = receive_message(&sender);
//check message contents
if (msg->mtype == DEFAULT && msg->mtext[0] == MSG_TEXT_1){
test_status[0] = TEST_SUCCESS;//TEST 1: Message contents same as when sent
} else {
test_status[0] = TEST_FAILURE;//message contents incorrect
}
release_memory_block(msg);
//Done testing
set_process_priority(pid, LOWEST);
#ifdef _DEBUG_HOTKEYS
// Force this process to be BLOCKED_ON_RECEIVE
receive_message(NULL);
#endif // _DEBUG_HOTKEYS
while (1) {
release_processor();
}
}
示例3: main
int main () {
int socket_desc = init();
char *message = "GET /var/14 HTTP/1.1\r\nHost:pb-homework.appspot.com\r\n\r\n";
send_message(socket_desc, message);
char server_reply[2000];
receive_message(server_reply, socket_desc);
char *secret_ptr = strstr(server_reply, "secret=");
char *message2=malloc(sizeof(char)*100);
sprintf(message2, "GET /var/14?%s HTTP/1.1\r\nHost:pb-homework.appspot.com\r\n\r\n", secret_ptr);
message=message2;
send_message(socket_desc, message);
receive_message(server_reply, socket_desc);
int result = count_result(server_reply);
char *message3=malloc(sizeof(char)*100);
sprintf(message3, "POST /var/14 HTTP/1.1\r\nHost:pb-homework.appspot.com\r\nContent-length: 8\r\n\r\nresult=%d", result);
message=message3;
send_message(socket_desc, message);
receive_message(server_reply, socket_desc);
close(socket_desc);
}
示例4: receive
/** Receive data.
*
* \warning You should not rely on receiving a single specific data element
* with the fast_client and fast_server implementation. Expect data to get lost.
*
* \param [in,out] t data to be received
* \param [in] timeout_ms Maximum wait time in milliseconds to receive data.
* Timeout is set to 1 second by default.
* \returns true if data was received successfully.
* \returns false when receive timeout occurred.
* \throws ib_error on error
*/
virtual bool receive(T &t, int timeout_ms = 1000)
{
IB_ASSERT(network_entity::_s, ib_error::EINVALIDSOCKET);
io::ensure_cleanup_partial_messages ecpm(this->get_socket());
const bool has_wait = (timeout_ms != 0);
const int max_skip = _enable_skip ? _recv_skip : 0;
int k = max_skip;
bool has_data = false;
while (k >= 0 && receive_message(t, ZMQ_DONTWAIT)) {
--k;
}
// Received at least one message from queue.
if (k != max_skip) {
return true;
}
// We haven't received anything. See if waiting is ok.
if (has_wait && io::is_data_pending(*network_entity::_s, timeout_ms)) {
receive_message(t, 0);
return true;
} else {
return false;
}
}
示例5: proc1
//TC 1: Delayed message sending & no preemption
void proc1(void) {
MSG_BUF* envelope = NULL;
char* msg = "SE 350";
uart1_put_string("\n\r");
uart1_put_string("G003_test: START\n\r");
uart1_put_string("G003_test: total ");
uart1_put_char(total + 48);
uart1_put_string(" tests\n\r");
prev_pid = 1;
envelope = (MSG_BUF*)request_memory_block();
strcpy(envelope->mtext, msg);
delayed_send(1, envelope, 5000);
envelope = (MSG_BUF*)receive_message(NULL);
if (strcmp(envelope->mtext, msg) == 0) {
prev_success = 1;
} else {
prev_success = 0;
}
release_memory_block(envelope);
if (prev_success) {
uart1_put_string("G003_test: test ");
uart1_put_char(1 + 48);
uart1_put_string(" OK\n\r");
pass = pass + 1;
} else {
uart1_put_string("G003_test: test ");
uart1_put_char(1 + 48);
uart1_put_string(" FAIL\n\r");
}
//TC 2: Blocked on receive & preemption
envelope = (MSG_BUF*)receive_message(NULL);
prev_success = 1; // Checks if you ever get here.
release_memory_block(envelope);
if (prev_success) {
uart1_put_string("G003_test: test ");
uart1_put_char(2 + 48);
uart1_put_string(" OK\n\r");
pass = pass + 1;
} else {
uart1_put_string("G003_test: test ");
uart1_put_char(2 + 48);
uart1_put_string(" FAIL\n\r");
}
while (1) {
release_processor();
}
}
示例6: segment_display
// display thread handler
void segment_display(void const * arg){
uint16_t LED_pins[4] = { GPIO_Pin_12, GPIO_Pin_13, GPIO_Pin_14, GPIO_Pin_15 };
int count = 0;
char key = DUMMY_KEY, led = '1';
int mode = TEMP_MODE;
float temperature = 50.0;
float pitch = 0.0;
display_init();
float data;
while(1){
osSignalWait(DISPLAY_READY, osWaitForever);
// try to get the keypad message
if (receive_message(&data, keypad_queue)){
key = (char)(((int)data) + '0');
// figure out which type of key was pressed (i.e. mode or led) and adjust variables accordingly.
if (key == TEMP_MODE_KEY || key == MEMS_MODE_KEY){
mode = key == TEMP_MODE_KEY ? TEMP_MODE : MEMS_MODE;
} else {
led = key;
}
}
// try to get the pitch message
if (receive_message(&data, pitch_queue)){
pitch = data;
}
// try to get the temperature message
if (receive_message(&data, temp_queue)){
temperature = data;
}
GPIO_ResetBits(GPIOD, GPIO_SEGMENT_PINS);
GPIO_ResetBits(GPIOE, GPIO_DIGIT_SELECT_PINS);
// run the display effect depending on whether or not an alarm is triggerd and the type of mode.
if (temperature < ALARM_THRESHOLD || (count % (2 * TIM3_DESIRED_RATE)) < TIM3_DESIRED_RATE) {
if (mode == TEMP_MODE){
GPIO_ResetBits(GPIOD, ALL_LED_PINS);
display_value(temperature, count, TEMP_MODE);
} else {
display_value(pitch, count, MEMS_MODE);
}
}
if (mode == MEMS_MODE){
display_LED(pitch, count, LED_pins[(led - '1')]);
}
count++;
}
}
示例7: test_message
int
/*main( int argc, char **argv )
{*/
test_message(){
char *comeback, one[] = "the quick brown fox", two[]="jumps over the lazy dog";
pthread_t receive = pthread_self();
int size;
/* Don't start if we can't get the message system working. */
if (messages_init() == MSG_OK) {
/* Send and receive from destination process 1 (without threads running, we'll receive on thread 1 in torch's pthread implementation. */
/* Send a single message for starters. */
if (send_message_to_thread( receive, one, strlen(one)+1) != MSG_OK) {
printf( "first failed\n" );
}
if (receive_message( &receive, &comeback, &size) == MSG_OK) {
printf ("received message 1--%s--size %d\n", comeback, size );
} else {
printf ("first receive failed\n");
}
/* Ensure that we can have some capacity in our message system. */
if (send_message_to_thread( receive, two, strlen(two)+1) != MSG_OK) {
printf( "second 1 failed\n" );
}
if (send_message_to_thread( receive, one, strlen(one)+1) != MSG_OK) {
printf( "second 2 failed\n" );
}
if (receive_message( &receive, &comeback, &size) == MSG_OK) {
printf ("received message 2--%s--size %d\n", comeback, size );
} else {
printf ("second 1 receive failed\n");
}
if (receive_message( &receive, &comeback, &size) == MSG_OK) {
printf ("received message 3--%s--size %d\n", comeback, size );
} else {
printf ("second 2 receive failed\n");
}
/* Clean up the message system. */
messages_end();
}
return 1;
}
示例8: state_check_seeder
static void state_check_seeder()
{
receive_message();
if(role == SEEDER) {
//propagate seederness
message_out(EMPTY, id, M_SEEDER);
} else {
enable_tx = 0;
message_out(EMPTY, EMPTY, EMPTY);
}
_delay_ms(10);
++counter;
if(counter >= CHECK_SEEDER_COUNT) {
//after CHECK_SEEDER_COUNT rounds, check, whether enough seeders are visible
RESET_COUNTER;
if(n_of_seeders() < (MIN_SEEDERS - (role == SEEDER))) {
//if not, provoke new bottom election
enable_tx = 1;
message_out(EMPTY, EMPTY, M_NOT_ENOUGH_SEEDS);
_delay_ms(100);
state = ELECT_SEED_BOTTOM;
if(role != SEEDER)
role = BOTTOM_SEEDER;
} else {
enable_tx = 1;
state = AWAIT_R_R;
RESET_COUNTER;
}
}
}
示例9: test_proc_p2_3
/* Sends message to user process 2 */
void test_proc_p2_3(void) {
int result_pid = 2;
msg_buf_t* msg_envelope = 0;
char* sent_msg = "OS";
char* received_msg = "SE350";
msg_envelope = (msg_buf_t*)request_memory_block();
strncpy(msg_envelope->msg_data, sent_msg, 2);
send_message(PID_P2, msg_envelope);
msg_envelope = (msg_buf_t*)receive_message(NULL);
if (strcmp(msg_envelope->msg_data, received_msg) == 5) {
printf("G005_test: test 3 OK\r\n");
} else {
printf("G005_test: test 3 FAIL\r\n");
test_results[result_pid] = 0;
}
release_memory_block(msg_envelope);
test_ran[result_pid] = 1;
set_process_priority(g_test_procs[result_pid].pid, 3);
while (1) {
release_processor();
}
}
示例10: test_proc_p2_1
/* Delayed Send Test */
void test_proc_p2_1(void) {
int result_pid = 0;
msg_buf_t* msg_envelope = NULL;
char* msg = "Hello";
msg_envelope = (msg_buf_t*)request_memory_block();
strncpy(msg_envelope->msg_data, msg, 5);
delayed_send(PID_P1, msg_envelope, CLOCK_INTERVAL);
msg_envelope = (msg_buf_t*)receive_message(NULL);
if (strcmp(msg_envelope->msg_data, msg) == 5) {
printf("G005_test: test 1 OK\r\n");
} else {
printf("G005_test: test 1 FAIL\r\n");
test_results[result_pid] = 0;
}
release_memory_block(msg_envelope);
test_ran[result_pid] = 1;
set_process_priority(g_test_procs[result_pid].pid, 3);
while (1) {
release_processor();
}
}
示例11: process_priority_proc
void process_priority_proc(void) {
msg_buf* message;
message = (msg_buf*)request_memory_block();
message->mtype = KCD_REG;
copy_string("%C", message->mtext);
send_message(PID_KCD, message);
while (1){
int neg_1 = -1;
int mtext_len;
msg_buf* message = (msg_buf*) receive_message(&neg_1);
if (message == NULL) {
continue;
}
mtext_len = str_len(message->mtext);
if (message->mtext[1] == 'C' && (mtext_len == 8 || mtext_len == 7)) {
int p_id;
int p_priority;
if (mtext_len == 7) {
// %C X Y
p_id = message->mtext[3] - '0';
p_priority = message->mtext[5] - '0';
} else {
// %C XX Y
p_id = (message->mtext[3] - '0') * 10;
p_id = message->mtext[4] - '0';
p_priority = message->mtext[6] - '0';
}
if (set_process_priority(p_id, p_priority) == RTX_ERR) {
msg_buf* err_msg = (msg_buf*)request_memory_block();
Node* msg_node = (Node*)request_memory_block();
err_msg->mtype = CRT_DISPLAY;
copy_string("Invalid Command for set process priority\n\r", err_msg->mtext);
//sends error to CRT
msg_node->sender_id = PID_SET_PRIO;
msg_node->receiving_id = PID_CRT;
msg_node->data = err_msg;
send_message_node(msg_node);
}
} else {
msg_buf* err_msg = (msg_buf*)request_memory_block();
Node* msg_node = (Node*)request_memory_block();
err_msg->mtype = CRT_DISPLAY;
copy_string("Invalid Format for set process priority\n\r", err_msg->mtext);
//sends error to CRT
msg_node->sender_id = PID_SET_PRIO;
msg_node->receiving_id = PID_CRT;
msg_node->data = err_msg;
send_message_node(msg_node);
}
release_memory_block(message);
}
}
示例12: TNC_IMC_ReceiveMessageLong
/**
* see section 3.8.6 of TCG TNC IF-IMV Specification 1.3
*/
TNC_Result TNC_IMC_ReceiveMessageLong(TNC_IMCID imc_id,
TNC_ConnectionID connection_id,
TNC_UInt32 msg_flags,
TNC_BufferReference msg,
TNC_UInt32 msg_len,
TNC_VendorID msg_vid,
TNC_MessageSubtype msg_subtype,
TNC_UInt32 src_imv_id,
TNC_UInt32 dst_imc_id)
{
imc_state_t *state;
imc_msg_t *in_msg;
TNC_Result result;
if (!imc_os)
{
DBG1(DBG_IMC, "IMC \"%s\" has not been initialized", imc_name);
return TNC_RESULT_NOT_INITIALIZED;
}
if (!imc_os->get_state(imc_os, connection_id, &state))
{
return TNC_RESULT_FATAL;
}
in_msg = imc_msg_create_from_long_data(imc_os, state, connection_id,
src_imv_id, dst_imc_id,msg_vid, msg_subtype,
chunk_create(msg, msg_len));
result =receive_message(in_msg);
in_msg->destroy(in_msg);
return result;
}
示例13: prcv_mbf
ER
prcv_mbf(ID mbfid, void *msg)
{
MBFCB *p_mbfcb;
uint_t msgsz;
bool_t dspreq;
ER_UINT ercd;
LOG_PRCV_MBF_ENTER(mbfid, msg);
CHECK_TSKCTX_UNL();
CHECK_MBFID(mbfid);
p_mbfcb = get_mbfcb(mbfid);
t_lock_cpu();
if ((msgsz = receive_message(p_mbfcb, msg, &dspreq)) > 0U) {
if (dspreq) {
dispatch();
}
ercd = (ER_UINT) msgsz;
}
else {
ercd = E_TMOUT;
}
t_unlock_cpu();
error_exit:
LOG_PRCV_MBF_LEAVE(ercd, msg);
return(ercd);
}
示例14: read_char
/* read char */
char read_char() {
char ch;
MESSAGE msg;
if (has_network_socket()) {
int st;
msg.msg_type = MSG_GRAPH;
msg.param.pword[1] = GraphRes;
msg.param.pword[0] = GRAPH_READCHAR;
send_to_graph(&msg);
while (TRUE) {
st = receive_message(network_socket, &msg);
if (st == 0) {
if ((msg.msg_type == MSG_GRAPH) &&
(msg.param.pword[0] == GRAPH_READCHAR_RESPONSE)) {
ch = msg.param.pchar;
break;
}
}
}
return (ch);
} else {
ch = getchar();
return (ch);
}
}
示例15: priority_switch_command_handler
void priority_switch_command_handler()
{
// register the command
MessageEnvelope * kcd_msg = (MessageEnvelope *)request_memory_block();
kcd_msg->type = TYPE_REGISTER_CMD;
kcd_msg->msg[0] = '%';
kcd_msg->msg[1] = 'C';
send_message(KCD_PID, kcd_msg);
// loop waiting for messages from the KCD
while (1) {
MessageEnvelope * cmd = receive_message(NULL);
if (cmd->msg[0] != '%' || cmd->msg[1] != 'C' || cmd->msg[2] != ' ') {
str_copy((BYTE *)"Command was invalid\n\r", (BYTE *)cmd->msg);
send_message(CRT_PID, cmd);
continue;
}
UINT32 i;
// find the space in the argument and put a null there so ascii_to_int
// can parse the two numbers independently
for (i = 3; cmd->msg[i] != NULL; i ++) {
if (cmd->msg[i] == ' ') {
cmd->msg[i] = NULL;
break;
}
}
SINT32 pid = ascii_to_int(&cmd->msg[3]);
SINT32 priority = ascii_to_int(&cmd->msg[i + 1]);
if (pid == -1) {
str_copy((BYTE *)"PID was invalid\n\r", (BYTE *)cmd->msg);
send_message(CRT_PID, cmd);
continue;
}
if (priority == -1) {
str_copy((BYTE *)"Priority was invalid\n\r", (BYTE *)cmd->msg);
send_message(CRT_PID, cmd);
continue;
}
//rtx_dbug_outs_int("PID: ", pid);
//rtx_dbug_outs_int("Priority: ", priority);
int success = set_process_priority(pid, priority);
if (success != 0) {
str_copy((BYTE *)"Cannot change that process to that priority\n\r", (BYTE *)cmd->msg);
send_message(CRT_PID, cmd);
continue;
}
str_copy((BYTE *)"Priority change successful\n\r", (BYTE *)cmd->msg);
send_message(CRT_PID, cmd);
}
}