All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.voovan.network.aio.AcceptCompletionHandler Maven / Gradle / Ivy

There is a newer version: 4.3.8
Show newest version
package org.voovan.network.aio;

import org.voovan.network.EventTrigger;

import java.io.IOException;
import java.nio.channels.AsynchronousSocketChannel;
import java.nio.channels.CompletionHandler;

/**
 * Aio Accept 事件
 * 
 * @author helyho
 *
 * Voovan Framework.
 * WebSite: https://github.com/helyho/Voovan
 * Licence: Apache v2 License
 */
public class AcceptCompletionHandler implements CompletionHandler{

	public AcceptCompletionHandler(){
	}
	
	@Override
	public void completed(AsynchronousSocketChannel socketChannel, AioServerSocket serverSocket) {
		try {
			//接续接收 accept 请求
			serverSocket.catchAccept();
			
			AioSocket socket = new AioSocket(serverSocket,socketChannel);
			
			//触发 Accept 事件
			EventTrigger.fireAccept(socket.getSession());
			
			
		} catch (IOException e) {
			EventTrigger.fireException(null, e);
		}
	}

	@Override
	public void failed(Throwable exc, AioServerSocket attachment) {
		if(exc instanceof Exception){
			//触发 onException 事件
			EventTrigger.fireException(null, ( Exception)exc);
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy