Beispiel #1
0
static int ol_tcp_acc_set_opts(outlet_t *ol, uint8_t *data, int dlen)
{
	uint8_t *p = data;
	int left = dlen;

	while (left > 0)
	{
		int opt = *p++;
		left--;
		if (left < 4)
			return -BAD_ARG;
		uint32_t val = GET_UINT_32(p);
		p += 4;
		left -= 4;

		switch (opt)
		{
		case INET_OPT_PRIORITY:
			//
			// There is a priority setting in a PCB. It is always set to high
			// value to avoid closing of open connections when the stack runs
			// out of memory. Thus the option is ignored.
			//
			//printk("tcp_set_opts: unsupported option SO_PRIORITY ignored\n");
			break;

#if LING_WITH_LWIP
		case INET_OPT_TOS:
			ol->tcp->tos = (uint8_t)val;
			break;
#endif

		case TCP_OPT_NODELAY:
			//
			// Nagle's algo fights silly window syndrome. What is its
			// relationship to not delaying send?
			//
			ol_tcp_set_nodelay(ol, val);
			break;

		default:
			if (inet_set_opt(ol, opt, val) < 0)
				return -BAD_ARG;
		}
	}

	return 0;
}
Beispiel #2
0
static int ol_tcp_set_opts(outlet_t *ol, uint8_t *data, int dlen)
{
	uint8_t *p = data;
	int left = dlen;
	int saved_active = ol->active;

	while (left > 0)
	{
		int opt = *p++;
		left--;
		if (left < 4)
			return -BAD_ARG;
		uint32_t val = GET_UINT_32(p);
		p += 4;
		left -= 4;

		switch (opt)
		{
		case INET_OPT_RCVBUF:
			if (val >= 0x80000000)
				return -BAD_ARG;
			if (val > ol->max_recv_bufsize)
			{
				memnode_t *node = nalloc_N(val);
				if (node == 0)
				{
					// We may return -NO_MEMORY here; a more conservative
					// approach is to ignore the option and continue
					printk("ol_tcp_set_opts: cannot expand recv_buffer to %d byte(s)\n", val);
					continue;
				}
				ol->recv_bufsize = val;
				assert(ol->recv_buf_off <= ol->recv_bufsize); // no truncation
				memcpy(node->starts, ol->recv_buffer, ol->recv_buf_off);
				ol->max_recv_bufsize = (void *)node->ends -(void *)node->starts;
				ol->recv_buffer = (uint8_t *)node->starts;
				nfree(ol->recv_buf_node);
				ol->recv_buf_node = node;
				// ol->recv_buf_off stays the same
			}
			else
				ol->recv_bufsize = val;
			break;

		case INET_OPT_PRIORITY:
			//
			// There is a priority setting in a PCB. It is always set to high
			// value to avoid closing of open connections when the stack runs
			// out of memory. Thus the option is ignored.
			//
			//printk("tcp_set_opts: unsupported option SO_PRIORITY ignored\n");
			break;

		case INET_OPT_TOS:
			ol->tcp->tos = (uint8_t)val;
			break;

		case TCP_OPT_NODELAY:

			//
			// Nagle's algo fights silly window syndrome. What is its
			// relationship to not delaying send?
			//
			if (val)
				tcp_nagle_disable(ol->tcp);
			else
				tcp_nagle_enable(ol->tcp);
			break;

		default:
			if (inet_set_opt(ol, opt, val) < 0)
				return -BAD_ARG;
		}
	}

	//
	// If 'active' option was set among other options, then act immediately to
	// deliver a buffered packet, if any.
	//
	
	if (saved_active == INET_PASSIVE && ol->active != INET_PASSIVE)
	{
		proc_t *cont_proc = scheduler_lookup(ol->owner);
		assert(cont_proc != 0);
		recv_bake_packets(ol, cont_proc);
	}

	return 0;
}