예제 #1
0
파일: tunnel.go 프로젝트: simia-tech/iris
// Creates a new relay tunnel and associated buffers.
func (r *relay) newTunnel(id uint64, tun *iris.Tunnel) *tunnel {
	return &tunnel{
		id:  id,
		tun: tun,
		rel: r,

		atoiSize: queue.New(),
		atoiData: queue.New(),
		atoiSign: make(chan struct{}, 1),
		itoaSign: make(chan struct{}, 1),

		quit: make(chan chan error),
	}
}
예제 #2
0
파일: tunnel.go 프로젝트: ibmendoza/iris-go
func (c *Connection) newTunnel() (*Tunnel, error) {
	c.tunLock.Lock()
	defer c.tunLock.Unlock()

	// Make sure the connection is still up
	if c.tunLive == nil {
		return nil, ErrClosed
	}
	// Assign a new locally unique id to the tunnel
	tunId := c.tunIdx
	c.tunIdx++

	// Assemble and store the live tunnel
	tun := &Tunnel{
		id:   tunId,
		conn: c,

		itoaBuf:  queue.New(),
		itoaSign: make(chan struct{}, 1),
		atoiSign: make(chan struct{}, 1),

		init: make(chan bool),
		term: make(chan struct{}),

		Log: c.Log.New("tunnel", tunId),
	}
	c.tunLive[tunId] = tun

	return tun, nil
}
예제 #3
0
파일: thread.go 프로젝트: simia-tech/iris
// Creates a thread pool with the given concurrent thread capacity.
func NewThreadPool(cap int) *ThreadPool {
	t := &ThreadPool{
		tasks: queue.New(),
		idle:  cap,
		total: cap,
	}
	t.done = sync.NewCond(&t.mutex)
	return t
}
예제 #4
0
// Simple usage example that inserts the numbers 0, 1, 2 into a queue and then
// removes them one by one, printing them to the standard output.
func Example_usage() {
	// Create a queue an push some data in
	q := queue.New()
	for i := 0; i < 3; i++ {
		q.Push(i)
	}
	// Pop out the queue contents and display them
	for !q.Empty() {
		fmt.Println(q.Pop())
	}
	// Output:
	// 0
	// 1
	// 2
}