Example #1
0
int
init_gtm_master(void)
{
	int rc;
	cmdList_t *cmdList;

	elog(INFO, "Initialize GTM master\n");
	cmdList = initCmdList();

	/* Kill current gtm, build work directory and run initgtm */

	addCmd(cmdList, prepare_initGtmMaster());
	rc = doCmdList(cmdList);
	cleanCmdList(cmdList);
	elog(INFO, "Done.\n");
	return(rc);
}
Example #2
0
int
kill_gtm_slave(void)
{
	cmdList_t *cmdList;
	cmd_t *cmdKill;
	int rc;

	elog(INFO, "Kill GTM slave\n");
	cmdList = initCmdList();
	if ((cmdKill = prepare_killGtmSlave()))
	{
		addCmd(cmdList, cmdKill);
		rc = doCmdList(cmdList);
		cleanCmdList(cmdList);
		return(rc);
	}
	else return 1;
}
Example #3
0
int
kill_gtm_master(void)
{
	cmdList_t *cmdList;
	cmd_t *cmd_killGtmMaster;
	int rc;

	elog(INFO, "Kill GTM master\n");
	cmdList = initCmdList();
	if ((cmd_killGtmMaster = prepare_killGtmMaster()))
	{
		addCmd(cmdList, cmd_killGtmMaster);
		rc = doCmdList(cmdList);
		cleanCmdList(cmdList);
		return(rc);
	}
	return 1;
}
Example #4
0
int
stop_gtm_slave(void)
{
	cmdList_t *cmdList;
	cmd_t *cmd;
	int rc;

	elog(INFO, "Stop GTM slave\n");
	cmdList = initCmdList();
	if ((cmd = prepare_stopGtmSlave()))
	{
		addCmd(cmdList, cmd);
		rc = doCmdList(cmdList);
		cleanCmdList(cmdList);
		return(rc);
	}
	return 1;
}
Example #5
0
int
clean_gtm_slave(void)
{
	cmdList_t *cmdList;
	int rc;

	elog(NOTICE, "Clearing gtm slave resources.\n");
	if (!isVarYes(VAR_gtmSlave) || is_none(VAR_gtmSlaveServer))
	{
		elog(ERROR, "ERROR: gtm slave is not configured.\n");
		return 1;
	}
	cmdList = initCmdList();
	addCmd(cmdList, prepare_cleanGtmSlave());
	rc = doCmdList(cmdList);
	cleanCmdList(cmdList);
	elog(NOTICE, "Done.\n");
	return(rc);
}
Example #6
0
int
init_gtm_slave(void)
{
	cmdList_t *cmdList;
	cmd_t *cmdInitGtm;
	int rc;

	elog(INFO, "Initialize GTM slave\n");
	cmdList = initCmdList();
	if ((cmdInitGtm = prepare_initGtmSlave()))
	{
		addCmd(cmdList, cmdInitGtm);
		/* Do all the commands and clean */
		rc = doCmdList(cmdList);
		cleanCmdList(cmdList);
		elog(INFO, "Done.\n");
		return(rc);
	}
	return 1;
}
Example #7
0
void CDMDebugFrame::on(DebugManagerListener::DebugCommand, const string& aLine, uint8_t aType, uint8_t aDirection, const string& ip) noexcept {
	if(bFilterIp && Text::toT(ip).find(sFilterIp) == tstring::npos) {
		return;
	}

	string cmd;
	switch(aType) {
		case DebugManager::TYPE_HUB:
			if(!showHubCommands)
				return;
			cmd = "Hub:";
			break;
		case DebugManager::TYPE_CLIENT:
			if(!showTCPCommands)
				return;
			cmd = "Client (TCP):";
			break;
		case DebugManager::TYPE_CLIENT_UDP:
			if(!showUDPCommands)
				return;
			cmd = "Client (UDP):";
			break;
		default: dcassert(0);
	}

	cmd += "\t\t";

	if (aDirection == DebugManager::INCOMING) {
		cmd += "[Incoming]";
	} else {
		cmd += "[Outgoing]";
	}

	cmd += "[" + ip + "]\t \t" + aLine;

	addCmd(cmd);
}
Example #8
0
 inline void add(MultiCmd &cmds, Rest&...args) {
     addCmd(cmds);
     add(args...);
 }
Example #9
0
 inline void add(CmdBase &cmd, Rest&...args) {
     addCmd(cmd);
     add(args...);
 }
Example #10
0
int main(int argc, char **argv)
{
	int c;
	risp_t *risp;
	int sent;
	char *srv = "127.0.0.1";
	char *filename = NULL;
	int port = DEFAULT_PORT;
	int avail;
	int processed;
	int len;
	int done = 0, t;

	node_t node;

	// initialise the node data.
	node.handle = INVALID_HANDLE;
	node.verbose = 0;
	node.finished = 0;
	expbuf_init(&node.in, 1024);
	expbuf_init(&node.out, 1024);
	expbuf_init(&node.data.file, 0);
	expbuf_init(&node.data.data, 0);
	node.data.op = CMD_NOP;
	node.data.size = 0;
	node.data.offset = 0;

	node.filehandle = INVALID_HANDLE;
	node.size = 0;
	node.offset = 0;


	while ((c = getopt(argc, argv, "f:p:s:v")) != -1) {
		switch (c) {
			case 'f':
				filename = optarg;
				assert(filename != NULL);
				break;
			case 'p':
				port = atoi(optarg);
				assert(port > 0);
				break;
			case 's':
				srv = optarg;
				assert(srv != NULL);
				break;
			case 'v':
				node.verbose ++;
				break;
			default:
				fprintf(stderr, "Illegal argument \"%c\"\n", c);
				return 1;
		}
	}

	if (filename == NULL) {
		fprintf(stderr, "Need a filename.\n\n");
		exit(1);
	}

	// get an initialised risp structure.
	risp = risp_init();
	if (risp == NULL) {
		printf("Unable to initialise RISP library.\n");
	}
	else {
		risp_add_command(risp, CMD_CLEAR, 	&cmdClear);
		risp_add_command(risp, CMD_EXECUTE, &cmdExecute);
		risp_add_command(risp, CMD_OFFSET,  &cmdOffset);
		risp_add_command(risp, CMD_SIZE,    &cmdSize);
		risp_add_command(risp, CMD_FILE,    &cmdFile);
		risp_add_command(risp, CMD_DATA,    &cmdData);
		risp_add_command(risp, CMD_PUT,     &cmdPut);
		risp_add_command(risp, CMD_GET,     &cmdGet);
		
		len = strlen(filename);
		assert(len < 256);

		assert(node.out.length == 0);
		
		addCmd(&node.out, CMD_CLEAR);
		addCmd(&node.out, CMD_GET);
		addCmdShortStr(&node.out, CMD_FILE, len, filename);
		addCmd(&node.out, CMD_EXECUTE);
		
		// and process it a lot of time.
		printf("Sending request for: %s\n", filename);
		
		// connect to the remote socket.
		node.handle = sock_connect(srv, port);
		if (node.handle <= 0) {
			printf("Unable to connect to %s:%d\n", srv, port);
		}
		else {
			while (sigtrap == 0 && node.finished == 0) {

				// continue to send data to the socket over and over as quickly as possible.
				while (node.out.length > 0) {
					assert(node.handle > 0);
					sent = sock_send(node.handle, node.out.data, node.out.length);
					if (sent < 0) { sigtrap ++; }
					else {
						assert(sent > 0);
						assert(sent <= node.out.length);
						if (sent == node.out.length) { expbuf_clear(&node.out); }
						else { expbuf_purge(&node.out, sent); }
					}	
				}

				// if we didn't generate a fail during the write, then we do a read.
				if (sigtrap == 0) {

					avail = node.in.max - node.in.length;
					if (avail < 1024) {
						expbuf_shrink(&node.in, 1024);
						avail = 1024;
					}

					sent = sock_receive(node.handle, node.in.data + node.in.length, avail);
					if (sent < 0) { sigtrap ++; }
					else {
						assert(sent > 0);
						node.in.length += sent;
						assert(node.in.length <= node.in.max);
						if (sent == avail) {
							// we filled the incoming buffer, so we need to double it.
							expbuf_shrink(&node.in, node.in.max * 2);
						}
						processed = risp_process(risp, &node, node.in.length, (unsigned char *) node.in.data);
// 						printf("Processed %d.\n", processed);
						if (processed > 0) {
							expbuf_purge(&node.in, processed);

							if (node.offset > 0 && node.size > 0) {
								t = (node.offset / (node.size/100));
								if (t > done) {
									done = t;
									printf("Done - %c%d\n", '%', done);
								}
							}
						}
					}
				}
			}
			
			// close the socket.
			if (node.handle >= 0) {
				close(node.handle);
			}
		}
	
		// clean up the risp structure.
		risp_shutdown(risp);
	}
	
	return 0;
}
Example #11
0
// The server is sending us a file.
void processPut(node_t *node)
{
	char filename[256];
	int flen;
	
	assert(node != NULL);

	if (node->filehandle == INVALID_HANDLE) {
		// we haven't opened the file yet.

		assert(node->size == 0);
		assert(node->offset == 0);

		if (node->data.file.length == 0 || node->data.size == 0 || node->data.offset != 0) {
			// the client did not provide the required details.
			addCmd(&node->out, CMD_CLEAR);
			addCmd(&node->out, CMD_FAIL);
			addCmd(&node->out, CMD_EXECUTE);
		}
		else {
			// we have the necessary details.

			strncpy(filename, node->data.file.data, node->data.file.length);
			filename[node->data.file.length] = '\0';
			node->filehandle = open(filename, O_WRONLY | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
			
			if (node->filehandle < 0) {
				if (node->verbose) printf("node:%d - unable to open file: %s\n", node->handle, filename);
				addCmd(&node->out, CMD_CLEAR);
				addCmd(&node->out, CMD_FAIL);
				addCmd(&node->out, CMD_EXECUTE);
				
				node->filehandle = INVALID_HANDLE;
			}
			else {
				node->size = node->data.size;
				node->offset = 0;
			}
		}
	}

	if (node->filehandle != INVALID_HANDLE) {
	
	//	if (node->verbose) printf("node:%d - sending file: %s\n", node->handle, filename);
				
		if (node->offset != node->data.offset) {
			if (node->verbose) printf("node:%d - offset mismatch\n", node->handle);
			addCmd(&node->out, CMD_CLEAR);
			addCmd(&node->out, CMD_FAIL);
			addCmd(&node->out, CMD_EXECUTE);

			close(node->filehandle);
			node->filehandle = INVALID_HANDLE;
			node->offset = 0;
			node->size = 0;
		}
		else {
				
			// get the data and write it to the file.
			flen = write(node->filehandle, node->data.data.data, node->data.data.length);
			assert(flen < 0 || flen == node->data.data.length);
			if (flen < 0) {
				// something happened... unable to write to file.
				if (node->verbose) printf("node:%d - unable to write.\n", node->handle);
			}
			else {
				node->offset += flen;
				assert(node->offset <= node->size);
				if (node->offset == node->size) {
					printf("Finished file.\n");
					close(node->filehandle);
					node->filehandle = INVALID_HANDLE;
					node->offset = 0;
					node->size = 0;
					node->finished = 1;
				}
			}
		}
	}
}
Example #12
0
File: rfxd.c Project: hyper/librisp
// the node is requesting a file.
void processGet(node_t *node) 
{
	unsigned int avail;
	char *filename;
	int flen;
	
	assert(node != NULL);
	
	if (node->data.file.length == 0) {
		// the client did not provide a filename...
		addCmd(&node->out, CMD_CLEAR);
		addCmd(&node->out, CMD_FAIL);
		addCmd(&node->out, CMD_EXECUTE);
	}
	else {
		
		// open the file and get the size of it.
		assert(node->filehandle == INVALID_HANDLE);
		
		flen = node->data.file.length;
		if (node->storepath != NULL) { flen += strlen(node->storepath) + 1; }
		filename = (char *) malloc(flen + 1);
		assert(filename);
		if (node->storepath != NULL) {
			strcpy(filename, node->storepath);
			strcat(filename, "/");
			strncat(filename, node->data.file.data, node->data.file.length);
			filename[flen] = '\0';
		}
		
		if (node->verbose) printf("node:%d - opening file: %s\n", node->handle, filename);
		
		node->filehandle = open(filename, O_RDONLY);
		if (node->filehandle < 0) {
			if (node->verbose) printf("node:%d - unable to open file: %s\n", node->handle, filename);
			addCmd(&node->out, CMD_CLEAR);
			addCmd(&node->out, CMD_FAIL);
			addCmd(&node->out, CMD_EXECUTE);
		}
		else {
		
			if (node->verbose) printf("node:%d - sending file: %s\n", node->handle, filename);
			
			// we've opened the file... now we need to determine its size.
			assert(node->size == 0);
			node->size = lseek(node->filehandle, 0, SEEK_END);
			lseek(node->filehandle, 0, SEEK_SET);

			if (node->verbose) printf("node:%d - file size: %d\n", node->handle, node->size);
			
			// offset should already be 0, needs to be because we are starting from the begining.
			assert(node->offset == 0);

			// we are going to be reading file data into the filebuf buffer.   Since this is the first GET. then we will just read in the data to the filebuf filling it if we can.

			assert(node->filebuf.max == 0);

			expbuf_shrink(&node->filebuf, 1024);
			
			avail = node->filebuf.max;
			if (node->size < avail) { avail = node->size; }
			assert(avail > 0);

			assert(avail <= node->filebuf.max);
			node->filebuf.length = read(node->filehandle, node->filebuf.data, avail);
			assert(node->filebuf.length > 0);
			assert(node->filebuf.length <= avail);

			addCmd(&node->out, CMD_CLEAR);
			addCmd(&node->out, CMD_PUT);
			addCmdShortStr(&node->out, CMD_FILE, node->data.file.length, node->data.file.data);
			addCmdLargeInt(&node->out, CMD_SIZE, node->size);
			addCmdLargeInt(&node->out, CMD_OFFSET, node->offset);
			addCmdLargeStr(&node->out, CMD_DATA, node->filebuf.length, node->filebuf.data);
			addCmd(&node->out, CMD_EXECUTE);
			
			assert(node->out.length <= node->out.max);

			if (node->verbose) printf("node:%d Sending %d (%d)\n", node->handle, node->filebuf.length, node->out.length);
			
			assert(node->sending == false);
			assert(node->offset == 0);
			
			node->sending = true;
			node->offset = node->filebuf.length;
		}
		assert(filename != NULL);
		free(filename); filename = NULL;
	}
}