RU/2: Форум. Общение пользователей и разработчиков OS/2 (eCS). : peek,c


Список сообщений | Написать новое | Ответить на сообщение | Домой Поиск:
Предыдущее сообщение | Следующее сообщение
From : GA
To : All
Subj : peek,c

/* peek utility for use with the Smalltalk AbxProcessPeekApp application.
* Compile with the command: cc -o peek peek.c.
*/

#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/errno.h>

#define DEFAULT_PORT 7172

void printUsage() {
printf("usage: peek [-p portnum] filename\n"); }

int getPortNum(char *argv[]) {

int port;

if (strcmp(argv[1], "-p") !=0) {
printf("Invalid option: %s\n", argv[1]);
return -1; }

port = atoi(argv[2]);
if (port < 1) {
printf("Invalid port given\n");
return -1; }

return port; }

int sendPeekRequest(int port, char* fileName) {

int sockfd;
struct sockaddr_in servaddr;

if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
printf("socket error: %d\n", errno);
return -1; }

memset(&servaddr, 0, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(port);
if (inet_addr(AF_INET, "127.0.0.1", &servaddr.sin_addr) < 0) {
printf("inet_addr error: %d\n", errno);
return -1; }

if (connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0) {
printf("connect error: %d\n", errno);
return -1; }

if (write(sockfd, fileName, strlen(fileName)) < 0) {
printf("send error: %d\n", errno);
close(sockfd);
return -1; }

close(sockfd);
return 0; }

void main(int argc, char *argv[]) {
int port;
char *fileName;
int i;

if ((argc != 2) & (argc != 4)) {
printUsage();
exit(1); }

if (argc == 4)
port = getPortNum(argv);
else
port = DEFAULT_PORT;

if (port == -1) {
printUsage();
exit(1); }

fileName = argv[argc - 1];

if (sendPeekRequest(port, fileName) < 0)
printf("Unable to send request to port: %d, filename: %s\n", port, fileName);
else
printf("Sent request to port: %d, filename: %s\n", port, fileName);
}

Read.txt:

Contents of processPeek.zip

readme.txt: this file
peek.c: source code for peek executable
processPeek.dat: contains Smalltalk application AbxProcessPeekApp

AbxProcessPeekApp (Smalltalk application side)
----------------------------------------------

If you include AbxProcessPeekApp in your packaged image, it will start up
automatically when your application starts. Upon starting up, it will listen
on some port (see below for information on choosing the port). When a client
connects to that port, the client is expected to send a string and then
disconnect. The string denotes the name of the file where AbxProcessPeekApp
will dump the state information. If you choose the name of an already
existing file, that file will be overwritten. The userid that started your
Smalltalk application must have permission to write to the file that the client
names.

Any errors that occur in the AbxProcessPeekApp will cause a message to
be written to the Transcript. If you wish, you can change this behavior by
modifying AbxProcessPeekSocketListener>>#reportError:.

By default, the AbxProcessPeekApp will use port 7172. If you wish, you may
select a different port by adding two lines to your .ini file. The following lines
will change the port for AbxProcessPeekApp to 8000:

[AbxProcessPeekSocketListener]
PortNumber=8000

The output file contains information about all of the sockets that are
currently managed by your Smalltalk application and also information about all
current processes. Depending on the behavior of your application, the size of
the file generated by AbxProcessPeekApp can vary between around 30K to 500K or
more in extreme cases.

You can shut the listener down by sending the string "**SHUTDOWN**" in place
of a filename. The method AbxProcessPeekSocketListener class>>#killDefault
will accomplish this. You can start the listener with the method
AbxProcessPeekSocketListener class>>#onPort:.


AbxProcessPeekSocketClient (Smalltalk client)
---------------------------------------------

You can send messages to your application that includes AbxProcessPeekApp with
the class AbxProcessPeekSocketClient. For example, execute the following code
to cause an application with AbxProcessPeekApp at address 99.98.97.96 on port
7172 to dump its state to the file "/tmp/peekOutput":

(AbxProcessPeekSocketClient connectToServerAtAddress: '99.98.97.96' port: 7172)
sendMessageToListener: '/tmp/peekOutput'


peek (c client)
------------------

You can create a command line client for peek by compiling peek.c. See the
comments at the top of this file for instructions for how to build it. peek.c
has only been compiled and tested on AIX; you will likely need to change it
for other platforms.

The result of this compilation, peek, is a simple command line utility that acts as a
client to AbxProcessPeekSocketListener. You provide peek with a filename and a port
(optional) on the command line. For example, if you are using the default port
(7172), invoke peek as follows:

peek /tmp/myDumpFile

If you have chosen a different port, say 8000, invoke peek as follows:

peek -p 8000 /tmp/myDumpFile

You can also use peek to shut down the AbxProcessPeekApp process in your
running Smalltalk application by sending the stop code string as follows:

peek **SHUTDOWN**

You cannot use the peek client to restart the AbxProcessPeekApp.

You must run peek on the same machine that your Smalltalk application is
running on. Once peek has completed, it will write a success or failure
message to standard out.

Download the whole file:

processpeek.zip






Wed 19 Nov 2003 17:25 Mozilla/4.61 [en] (OS/2; U)




Programmed by Dmitri Maximovich, Dmitry I. Platonoff, Eugen Kuleshov.
25.09.99 (c) 1999, RU/2. All rights reserved.
Rewritten by Dmitry Ban. All rights ignored.