TcpConnector::TcpConnector(QWidget *parent) : QWidget(parent) , mConnect(false) { socket = new QTcpSocket(this); connect(socket , SIGNAL(connected()), this, SLOT(sConnect())); connect(socket, SIGNAL(disconnected()), this, SLOT(sDisconnect())); connect(socket, SIGNAL(readyRead()), this, SLOT(readAndSplit())); connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(sError(QAbstractSocket::SocketError))); connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT( sState(QAbstractSocket::SocketState))); checkboxOnline = new QCheckBox(this); layout = new QHBoxLayout(this); layout->addWidget( checkboxOnline ); setLayout(layout); setEnabled(false); connect(checkboxOnline, SIGNAL(clicked(bool)), this, SLOT(online(bool))); checkboxOnline->setMinimumHeight( 19 ); checkboxOnline->setMaximumHeight( 19 ); setMinimumHeight( 19 ); setMaximumHeight( 19 ); checkboxOnline->setStyleSheet("margin: 0px; border: 1px red solid;"); setStyleSheet("margin: 0px; border: 1px red solid;"); layout->setMargin(0); }
int make_connection(uint32 ip, uint16 port, bool silent) { struct sockaddr_in remote_address; int fd; int result; fd = sSocket(AF_INET, SOCK_STREAM, 0); if(fd == -1) { ShowError(read_message("Source.common.make_connection"), error_msg()); return -1; } if(fd == 0) { // reserved ShowError(read_message("Source.common.make_connection2")); sClose(fd); return -1; } if(fd >= FD_SETSIZE) { // socket number too big ShowError("make_connection: New socket #%d is greater than can we handle! Increase the value of FD_SETSIZE (currently %d) for your OS to fix this!\n", fd, FD_SETSIZE); sClose(fd); return -1; } setsocketopts(fd); remote_address.sin_family = AF_INET; remote_address.sin_addr.s_addr = htonl(ip); remote_address.sin_port = htons(port); if(!silent) ShowStatus(read_message("Source.common.make_connect"), CONVIP(ip), port); result = sConnect(fd, (struct sockaddr *)(&remote_address), sizeof(struct sockaddr_in)); if(result == SOCKET_ERROR) { if(!silent) ShowError(read_message("Source.common.make_sConnect"), fd, error_msg()); do_close(fd); return -1; } //Now the socket can be made non-blocking. [Skotlex] set_nonblocking(fd, 1); if(fd_max <= fd) fd_max = fd + 1; sFD_SET(fd,&readfds); create_session(fd, recv_to_fifo, send_from_fifo, default_func_parse); session[fd]->client_addr = ntohl(remote_address.sin_addr.s_addr); return fd; }
int make_connection(uint32 ip, uint16 port) { struct sockaddr_in remote_address; int fd; int result; fd = sSocket(AF_INET, SOCK_STREAM, 0); if (fd == -1) { ShowError("make_connection: falha ao criar socket (codigo %d)!\n", sErrno); return -1; } if( fd == 0 ) {// reserved ShowError("make_connection: Socket #0 e reservado - Favor reportar isso!!!\n"); sClose(fd); return -1; } if( fd >= FD_SETSIZE ) {// socket number too big ShowError("Novo socket #%d e maior do que suportamos! aumente o valor de FD_SETSIZE (atualmente %d) para seu SO consertar isso!\n", fd, FD_SETSIZE); sClose(fd); return -1; } setsocketopts(fd); remote_address.sin_family = AF_INET; remote_address.sin_addr.s_addr = htonl(ip); remote_address.sin_port = htons(port); ShowStatus("Conectando a %d.%d.%d.%d:%i\n", CONVIP(ip), port); result = sConnect(fd, (struct sockaddr *)(&remote_address), sizeof(struct sockaddr_in)); if( result == SOCKET_ERROR ) { ShowError("make_connection: conexao falhou (socket #%d, codigo %d)!\n", fd, sErrno); do_close(fd); return -1; } //Now the socket can be made non-blocking. [Skotlex] set_nonblocking(fd, 1); if (fd_max <= fd) fd_max = fd + 1; sFD_SET(fd,&readfds); create_session(fd, recv_to_fifo, send_from_fifo, default_func_parse); session[fd]->client_addr = ntohl(remote_address.sin_addr.s_addr); return fd; }
int make_connection(uint32 ip, uint16 port) { struct sockaddr_in remote_address; int fd; int result; fd = sSocket(AF_INET, SOCK_STREAM, 0); if (fd == -1) { ShowError("make_connection: criação do socket falhou ("CL_RED"%s"CL_RESET")!\n", error_msg()); return -1; } if( fd == 0 ) {// reserved ShowError("make_connection: Socket #"CL_WHITE"0"CL_RESET" é reservado - Reporte isso!\n"); sClose(fd); return -1; } if( fd >= FD_SETSIZE ) {// socket number too big ShowError("make_connection: Novo socket #"CL_WHITE"%d"CL_RESET" é maior que o que suporta-se! Aumente o valor do FD_SETSIZE (atualemente "CL_WHITE"%d"CL_RESET") para seu SO consertar isso!\n", fd, FD_SETSIZE); sClose(fd); return -1; } setsocketopts(fd); remote_address.sin_family = AF_INET; remote_address.sin_addr.s_addr = htonl(ip); remote_address.sin_port = htons(port); ShowStatus("Conectando-se a "CL_WHITE"%d.%d.%d.%d"CL_RESET":"CL_WHITE"%i"CL_RESET"\n", CONVIP(ip), port); result = sConnect(fd, (struct sockaddr *)(&remote_address), sizeof(struct sockaddr_in)); if( result == SOCKET_ERROR ) { ShowError("make_connection: conexão falhou (soquete #"CL_WHITE"%d"CL_RESET", "CL_WHITE"%s"CL_RESET")!\n", fd, error_msg()); do_close(fd); return -1; } //Now the socket can be made non-blocking. [Skotlex] set_nonblocking(fd, 1); if (fd_max <= fd) fd_max = fd + 1; sFD_SET(fd,&readfds); create_session(fd, recv_to_fifo, send_from_fifo, default_func_parse); session[fd]->client_addr = ntohl(remote_address.sin_addr.s_addr); return fd; }
int make_connection(uint32 ip, uint16 port, struct hSockOpt *opt) { struct sockaddr_in remote_address; int fd; int result; fd = sSocket(AF_INET, SOCK_STREAM, 0); if (fd == -1) { ShowError("make_connection: socket creation failed (%s)!\n", error_msg()); return -1; } if( fd == 0 ) {// reserved ShowError("make_connection: Socket #0 is reserved - Please report this!!!\n"); sClose(fd); return -1; } if( fd >= FD_SETSIZE ) {// socket number too big ShowError("make_connection: New socket #%d is greater than can we handle! Increase the value of FD_SETSIZE (currently %d) for your OS to fix this!\n", fd, FD_SETSIZE); sClose(fd); return -1; } setsocketopts(fd,opt); remote_address.sin_family = AF_INET; remote_address.sin_addr.s_addr = htonl(ip); remote_address.sin_port = htons(port); if( !( opt && opt->silent ) ) ShowStatus("Connecting to %d.%d.%d.%d:%i\n", CONVIP(ip), port); result = sConnect(fd, (struct sockaddr *)(&remote_address), sizeof(struct sockaddr_in)); if( result == SOCKET_ERROR ) { if( !( opt && opt->silent ) ) ShowError("make_connection: connect failed (socket #%d, %s)!\n", fd, error_msg()); sockt->close(fd); return -1; } //Now the socket can be made non-blocking. [Skotlex] set_nonblocking(fd, 1); if (sockt->fd_max <= fd) sockt->fd_max = fd + 1; sFD_SET(fd,&readfds); create_session(fd, recv_to_fifo, send_from_fifo, default_func_parse); session[fd]->client_addr = ntohl(remote_address.sin_addr.s_addr); return fd; }
int make_connection(uint32 ip, uint16 port, struct hSockOpt *opt) { struct sockaddr_in remote_address = { 0 }; int fd; int result; fd = sSocket(AF_INET, SOCK_STREAM, 0); if (fd == -1) { ShowError("make_connection: Criacao de socket falhou (%s)!\n", error_msg()); return -1; } if( fd == 0 ) {// reserved ShowError("make_connection: Socket #0 esta reservado - Por favor reporte isso!!!\n"); sClose(fd); return -1; } if( fd >= FD_SETSIZE ) {// socket number too big ShowError("make_connection: Novo socket #%d e maior do que o limite suportado! Aumentando o valor para FD_SETSIZE (atualmente %d) seu SO deve corrigir isso!\n", fd, FD_SETSIZE); sClose(fd); return -1; } setsocketopts(fd,opt); remote_address.sin_family = AF_INET; remote_address.sin_addr.s_addr = htonl(ip); remote_address.sin_port = htons(port); if( !( opt && opt->silent ) ) ShowStatus("Conectando-se a %d.%d.%d.%d:%i\n", CONVIP(ip), port); result = sConnect(fd, (struct sockaddr *)(&remote_address), sizeof(struct sockaddr_in)); if( result == SOCKET_ERROR ) { if( !( opt && opt->silent ) ) ShowError("make_connection: Falha na conexao (socket #%d, %s)!\n", fd, error_msg()); sockt->close(fd); return -1; } //Now the socket can be made non-blocking. [Skotlex] set_nonblocking(fd, 1); if (sockt->fd_max <= fd) sockt->fd_max = fd + 1; sFD_SET(fd,&readfds); create_session(fd, recv_to_fifo, send_from_fifo, default_func_parse); session[fd]->client_addr = ntohl(remote_address.sin_addr.s_addr); return fd; }