Sending Mavlink request via USB does not finish

Hello Everyone,

Complete newcomer to the world of mavlink and Ardupilot.

I am trying to connect ArduPilot 2.8 from C++ from Mac via usb port and I have been using c_uart_interface_example code. The problem is that I can read from usb port but when I write back the program gets stuck at

const int bytesWritten = static_cast(write(fd, buf, len));

it does not crash but just keeps on waiting endlessly, and similarly the read thread stops as well. Interestingly, a little debugging shows that code goes beyond
pthread_mutex_lock(&lock); indicating that the write is not locked.

This is where I got so far,
I am getting heartbeats without any problem
my heartbeat looks like as follows,
heartbeat autopilot= 3
heartbeat base_mode= 81
heartbeat mavlink_version= 3
heartbeat type= 2
heartbeat system_status= 4

My sysid = 1 and compid = 1

Once I get heartbeat I am sending request for Attitude information, code is,

switch (message.msgid)

			mavlink_msg_heartbeat_decode(&message, &(current_messages.heartbeat));
			current_messages.time_stamps.heartbeat = get_time_usec();
			this_timestamps.heartbeat = current_messages.time_stamps.heartbeat;

			mavlink_msg_request_data_stream_pack(127, 0, &request_message,1,1, MAVLINK_MSG_ID_ATTITUDE, 1, 1);


			heartbeat_found =1;



And this is where the whole things keeps on waiting endlessly to write the data on serial port.

Any idea why this is happening ? Please let me know if any more info will be useful .