ARTSPConnection::onConnect(const sp<AMessage> &msg) int err = ::connect( mSocket, (const struct sockaddr *)&remote, sizeof(remote)); LOGE("%s L%d err = %d", __FUNCTION__, __LINE__, err); if (err < 0) { if (errno == EINPROGRESS) { // 正在连接中 sp<AMessage> msg = new AMessage(kWhatCompleteConnection, id()); msg->setMessage("reply", reply); msg->setInt32("connection-id", mConnectionID); msg->post();调用---------->
void ARTSPConnection::onMessageReceived(const sp<AMessage> &msg) { case kWhatCompleteConnection: onCompleteConnection(msg);调用---------->
ARTSPConnection::onCompleteConnection int res = select(mSocket + 1, NULL, &ws, NULL, &tv); CHECK_GE(res, 0); if (res == 0) { // Timed out. Not yet connected. LOGE("%s L%d -ECONNABORTED", __FUNCTION__, __LINE__); msg->post(); // 循环执行此函数检查是否connected return; }
2.1 在ARTSPConnection::onCompleteConnection成功连接后,发送检查接收数据的event
void ARTSPConnection::postReceiveReponseEvent() { if (mReceiveResponseEventPending) { return; } sp<AMessage> msg = new AMessage(kWhatReceiveResponse, id()); msg->post(); mReceiveResponseEventPending = true; }调用----------> 2.2 void ARTSPConnection::onMessageReceived(const sp<AMessage> &msg) {
void ARTSPConnection::onReceiveResponse() { int res = select(mSocket + 1, &rs, NULL, NULL, &tv); // LOGE("%s L%d select res = %d", __FUNCTION__, __LINE__, res); CHECK_GE(res, 0); if (res == 1) { MakeSocketBlocking(mSocket, true); bool success = receiveRTSPReponse(); // 2.3.1 MakeSocketBlocking(mSocket, false); LOGE("%s L%d select ==== success = %d", __FUNCTION__, __LINE__, success); if (!success) { // Something horrible, irreparable has happened. flushPendingRequests(); LOGE("%s L%d return ", __FUNCTION__, __LINE__); return; } } postReceiveReponseEvent(); // 循环执行此函数 }
继续调用……
2.3.1 bool ARTSPConnection::receiveRTSPReponse() {
--->