|
#include "lrs.h"
#define DIR_LEN 100
#define PATH_LEN 128
typedef long time_t;
#ifdef unix
char *filename = "/tmp/logfile.txt";
#else
char *filename = "logfile.txt";
#endif
Action()
{
char *ActualBuffer;
int NumberOfBytes;
long file, thetime;
char original_dir[DIR_LEN];
char original_path[PATH_LEN];
int id, id2;
time_t t;
char s[32];
//lr_start_transaction("connect");
//lr_rendezvous("connect");
lrs_create_socket("socket0", "TCP", "RemoteHost=<server>:5000", LrsLastArg);
//lr_end_transaction("connect", LR_AUTO);
//lr_start_transaction("send");
lrs_send("socket0", "buf0", LrsLastArg);
//lr_end_transaction("send", LR_AUTO);
lrs_receive("socket0", "buf1", LrsLastArg);
lrs_disable_socket("socket0", DISABLE_SEND_RECV);
lrs_get_buffer_by_name("buf1", &ActualBuffer, &NumberOfBytes);
lr_output_message("运行第 %s 轮,buffer size = %d", lr_eval_string("1"),NumberOfBytes);
lrs_save_param_ex("socket0", "user", ActualBuffer, 0, NumberOfBytes, "ascii", "new_parameter");
if(!getcwd(original_dir, DIR_LEN)) {
lr_output_message("getcwd error");
return -1;
}
lr_whoami(&id, NULL, NULL);
sprintf (original_path, "%s\\%d%ld%s", original_dir,id,time(&t), filename);
/* Create a new file */
if ((file = fopen(original_path, "w+" )) == NULL) {
lr_output_message("Unable to create %s", filename);
return -1;
}
/* Write the Vuser id and time */
lr_whoami(&id, NULL, NULL);
fprintf(file, "Vuser %d %ld\n", id, time(&t));
/* Now read what we've just written. Rewind to start of file */
//rewind(file);
//fscanf(file, "%s", &s);
//fscanf(file, "%d", &id2);
//fscanf(file, "%ld", &thetime);
//lr_output_message("%s %d %ld", s, id2, thetime);
fprintf(file, "%s", lr_eval_string("<new_parameter>"));
fclose(file);
//lr_output_message("buffer size = %d",NumberOfBytes);
//lrs_save_param_ex("socket0", "user", ActualBuffer, 0, NumberOfBytes, "ascii", "new_parameter");
//lrs_free_buffer(ActualBuffer);
//lr_output_message("The buffer contains \"%s\"\n", lr_eval_string("<new_parameter>"));
lrs_close_socket("socket0");
return 0;
} |
|