- Timestamp:
- 05/28/10 09:25:33 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/SkyQualityMonitor/sqm.cpp
r179 r217 3 3 Interface to the sky quality monitor (essentially a socket interface) 4 4 5 Terminate with CTRL-c. Note that socket is closed automatically by exit().5 Terminate with CTRL-c. Socket is closed automatically by exit(). 6 6 7 7 Oliver Grimm, September 2009 … … 39 39 // Open socket descriptor 40 40 if ((SocketDescriptor = socket(PF_INET, SOCK_STREAM, 0)) == -1) { 41 Srv. State(Srv.FATAL, "Could not open socket (%s)", strerror(errno));41 Srv.Message(Srv.FATAL, "Could not open socket (%s)", strerror(errno)); 42 42 } 43 43 … … 45 45 struct hostent *hostent = gethostbyname(Address); 46 46 if (hostent==0) { 47 Srv. State(Srv.FATAL, "Could not resolve host name '%s' (%s)", Address, hstrerror(h_errno));47 Srv.Message(Srv.FATAL, "Could not resolve host name '%s' (%s)", Address, hstrerror(h_errno)); 48 48 } 49 49 … … 54 54 55 55 if (connect(SocketDescriptor, (struct sockaddr *) &SocketAddress, sizeof(SocketAddress))==-1) { 56 Srv. State(Srv.FATAL, "Could not connect to server '%s' on port %d (%s)", Address, Port, strerror(errno));56 Srv.Message(Srv.FATAL, "Could not connect to server '%s' on port %d (%s)", Address, Port, strerror(errno)); 57 57 } 58 58 59 Srv. State(Srv.INFO, "Connected to server '%s' on port %d", Address, Port);59 Srv.Message(Srv.INFO, "Connected to server '%s' on port %d", Address, Port); 60 60 signal(SIGPIPE,SIG_IGN); // Do not kill process if writing to closed socket 61 61 … … 73 73 // Write read command to socket 74 74 if ((write(SocketDescriptor, READ_CMD, strlen(READ_CMD)))<1) { 75 Srv. State(Srv.ERROR, "Could not write read command '%s' to socket.", READ_CMD);75 Srv.Message(Srv.ERROR, "Could not write read command '%s' to socket.", READ_CMD); 76 76 } 77 77 … … 82 82 struct timeval WaitTime = {Period, 0}; 83 83 if (select(((int) SocketDescriptor)+1, &ReadFileDescriptor, NULL, NULL, &WaitTime)==-1) { 84 Srv. State(Srv.FATAL, "Error with select() (%s)", strerror(errno));84 Srv.Message(Srv.FATAL, "Error with select() (%s)", strerror(errno)); 85 85 } 86 86 87 87 if (!FD_ISSET(SocketDescriptor, &ReadFileDescriptor)) { 88 Srv. State(Srv.WARN, "Time-out of %d seconds expired before receiving response from socket", Period);88 Srv.Message(Srv.WARN, "Time-out of %d seconds expired before receiving response from socket", Period); 89 89 continue; 90 90 } … … 92 92 memset(Buffer, 0, BUF_SIZE); 93 93 if(read(SocketDescriptor, Buffer, BUF_SIZE) == 0) { 94 Srv. State(Srv.FATAL, "Server not existing anymore, exiting...\n");94 Srv.Message(Srv.FATAL, "Server not existing anymore, exiting...\n"); 95 95 } 96 96
Note:
See TracChangeset
for help on using the changeset viewer.