tailieunhanh - Beginning Linux Programming Third Edition phần 8

Gửi một phản ứng sử dụng quá trình ID của khách hàng được lưu trữ trong yêu cầu để giải quyết các tin nhắn: của cửa sổ chính. Sự kiện này được phát ra khi chúng ta cố gắng để đóng một cửa sổ, nhưng giới phê bình trước khi các GTK + tín hiệu tiêu diệt được gửi. | Semaphores Shared Memory and Message Queues serv_qid -1 cli_qid -1 5. The server read function reads a message of any type that is from any client from the queue and it returns the data part ignoring the type of the message. int read_request_from_client message_db_t rec_ptr struct msg_passed my_msg if DEBUG_TRACE printf d - read_request_from_client n getpid endif if msgrcv serv_qid void my_msg sizeof rec_ptr 0 0 -1 return 0 rec_ptr return 1 6. Sending a response uses the client process ID that was stored in the request to address the message int send_resp_to_client const message_db_t mess_to_send struct msg_passed my_msg if DEBUG_TRACE printf d - send_resp_to_client n getpid endif mess_to_send if msgsnd cli_qid void my_msg sizeof mess_to_send 0 -1 return 0 return 1 Try It Out Revising the Client Functions 1. When the client starts it needs to find the server and client queue identifiers. The client doesn t create the queues. This function will fail if the server isn t running as the message queues won t exist. int client_starting if DEBUG_TRACE printf d - client_starting n getpid endif serv_qid msgget key_t SERVER_MQUEUE 0666 if serv_qid -1 return 0 581 Chapter 14 cli_qid msgget key_t CLIENT_MQUEUE 0666 if cli_qid -1 return 0 return 1 2. As with the server when the client ends we set our file-scope variables to illegal values. This will catch any bugs where the client attempts to send messages after it has called client_ending. void client_ending if DEBUG_TRACE printf d - client_ending n getpid endif serv_qid -1 cli_qid -1 3. To send a message to the server we store the data inside our structure. Notice that we must set the message key. As 0 is an illegal value for the key leaving the key undefined would mean that it takes an apparently random value so this function could occasionally fail if the value happens to be 0. int send_mess_to_server message_db_t mess_to_send struct msg_passed .

crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.