Ejemplo n.º 1
0
/*
	Each socket has two write buffer list, high priority and low priority.

	1. send high list as far as possible.
	2. If high list is empty, try to send low list.
	3. If low list head is uncomplete (send a part before), move the head of low list to empty high list (call raise_uncomplete) .
	4. If two lists are both empty, turn off the event. (call check_close)
 */
static int
send_buffer(struct socket_server *ss, struct socket *s, struct socket_message *result) {
	assert(!list_uncomplete(&s->low));
	// step 1
	if (send_list(ss,s,&s->high,result) == SOCKET_CLOSE) {
		return SOCKET_CLOSE;
	}
	if (s->high.head == NULL) {
		// step 2
		if (s->low.head != NULL) {
			if (send_list(ss,s,&s->low,result) == SOCKET_CLOSE) {
				return SOCKET_CLOSE;
			}
			// step 3
			if (list_uncomplete(&s->low)) {
				raise_uncomplete(s);
			}
		} else {
			// step 4
			sp_write(ss->event_fd, s->fd, s, false);

			if (s->type == SOCKET_TYPE_HALFCLOSE) {
				force_close(ss, s, result);
				return SOCKET_CLOSE;
			}
		}
	}

	return -1;
}
Ejemplo n.º 2
0
int socket_server::send_buffer(struct socket * s, struct socket_message * result)
{
    assert(!list_uncomplete(&s->low));
    if (send_list(s, &s->high, result) == SOCKET_CLOSE) {
        return SOCKET_CLOSE;
    }
    if (s->high.head == nullptr) {
        if (s->low.head != nullptr) {
            if (send_list(s, &s->low, result) == SOCKET_CLOSE) {
                return SOCKET_CLOSE;
            }
            if (list_uncomplete(&s->low)) {
                raise_uncomplete(s);
            }
        } else {
            event_fd.write(s->fd, s, false);
            if (s->type == SOCKET_TYPE_HALFCLOSE) {
                force_close(s, result);
                return SOCKET_CLOSE;
            }
        }
    }

    return -1;
}