mtcp-stack / mtcp

mTCP: A Highly Scalable User-level TCP Stack for Multicore Systems
Other
1.98k stars 436 forks source link

What's the purpose of closeq_int #210

Open particle128 opened 5 years ago

particle128 commented 5 years ago

Hi eunyong14,

I'm confused in reading HandleApplicationCalls in core.c. What's the purpose of closeq_int? Is it equal to "ignoring the closeq stream if it's on the control list"? But if so, we do not even need this structure, right?

I should have missed something, and am really looking forward for your reply. Thanks very much.

        } else if (sndvar->on_control_list) {
            sndvar->on_closeq_int = TRUE;
            StreamInternalEnqueue(mtcp->closeq_int, stream);

...

    while (cnt++ < max_cnt) {
        stream = StreamInternalDequeue(mtcp->closeq_int);

        if (stream->sndvar->on_control_list) {
            StreamInternalEnqueue(mtcp->closeq_int, stream);

        } else if (stream->state != TCP_ST_CLOSED) {
            ...
                 } else {
                        ...
                 }
eunyoung14 commented 5 years ago

Hi,

closeq_int exists to defer the actions for the streams in the control list and invoke the actions again when conditions are met. For example, if there is another control packet to transmit prior to sending FIN, we have to wait until FIN is sent first.

There is also slight difference between closeq and closeq_int. closeq is a single-directional lock-free queue to deliver streams to close from an application thread to an mtcp thread. At the part of the code, we are deferring the action because the stream is in the control list. However, we cannot put the stream back into closeq since we are in an mtcp thread. So we made closeq_int that is only accessed inside mtcp thread.

I hope this answers your question.

particle128 commented 5 years ago

I see. Thanks a lot for your explanation. So, closeq_int means closeq internal, which is be used in the same mtcp thread, while closeq can be pushed in business thread and popped in mtcp thread, right?

eunyoung14 commented 5 years ago

You're right. closeq_int is for internal use whereas closeq is a queue for inter-thread communication.