#include <sys/types.h>#include <sys/wait.h>#include <sys/socket.h>#include <sys/time.h>#include <signal.h>#include <errno.h>#include <unistd.h>#include <netinet/in.h>#include <netdb.h>#include <arpa/inet.h>#include <pthread.h>#include <stdio.h>#include <cstdlib>#include <string>#include <deque>#include <exception>#include "GlobalDefinitions.h"Include dependency graph for ClientServerUtils.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.
Classes | |
| struct | Handshake |
| struct | QueryHeader |
| struct | SequenceHeader |
| struct | MatchHeader |
| struct | MatchInfo |
| class | NetworkException |
| class | BrokenSocketException |
| class | SocketInterface |
Defines | |
| #define | SERV_PORT 9877 |
| #define | SERV_VERSION 4 |
| #define | SA struct sockaddr |
| #define | LISTENQ 1024 |
| #define | MAXLINE 4096 |
| #define | __attribute__(x) |
Typedefs | |
| typedef void | Sigfunc (int) |
Enumerations | |
| enum | TableType { e2bitDNA = 0, e5bitProtein = 1, e5bitTranslatedDNA = 2 } |
| enum | SortModeType { eNoSort = 0, eSortByMatchLength = 1, eSortByPercentMatch = 2, eSortAndReturnSequence = 3 } |
Functions | |
| void | err_sys (const char *fmt,...) |
| void | sig_chld (int signo) |
| int | Accept (int fd, sockaddr *sa, socklen_t *salenptr) |
| void | Bind (int fd, const sockaddr *sa, socklen_t salen) |
| void | Listen (int fd, int backlog) |
| Sigfunc * | signal (int signo, Sigfunc *func) |
| Sigfunc * | Signal (int signo, Sigfunc *func) |
| void | Close (int fd) |
| pid_t | Fork (void) |
| int | Socket (int family, int type, int protocol) |
| ssize_t | readn (int fd, void *vptr, size_t n) |
| ssize_t | Readn (int fd, void *ptr, size_t nbytes) |
| ssize_t | writen (int fd, const void *vptr, size_t n) |
| void | Writen (int fd, void *ptr, size_t nbytes) |
| char * | Fgets (char *ptr, int n, FILE *stream) |
| void | Fputs (const char *ptr, FILE *stream) |
| void | Connect (int fd, const sockaddr *sa, socklen_t salen) |
Variables | |
| Handshake | packed |
| QueryHeader | packed |
| SequenceHeader | packed |
| MatchHeader | packed |
| MatchInfo | packed |
| #define __attribute__ | ( | x | ) |
Definition at line 70 of file ClientServerUtils.h.
| #define LISTENQ 1024 |
| #define MAXLINE 4096 |
Definition at line 58 of file ClientServerUtils.h.
Referenced by SocketInterface::checkSocketEmpty(), and sendQuery().
| #define SA struct sockaddr |
| #define SERV_PORT 9877 |
Definition at line 54 of file ClientServerUtils.h.
| #define SERV_VERSION 4 |
| typedef void Sigfunc(int) |
Definition at line 53 of file ClientServerUtils.h.
| enum SortModeType |
Definition at line 113 of file ClientServerUtils.h.
00114 { 00115 eNoSort = 0, 00116 eSortByMatchLength = 1, 00117 eSortByPercentMatch = 2, 00118 eSortAndReturnSequence = 3 // return matched ASCII seq to client 00119 };
| enum TableType |
Definition at line 96 of file ClientServerUtils.h.
00097 { 00098 e2bitDNA = 0, 00099 e5bitProtein = 1, 00100 e5bitTranslatedDNA = 2 00101 };
| int Accept | ( | int | fd, | |
| sockaddr * | sa, | |||
| socklen_t * | salenptr | |||
| ) |
Definition at line 74 of file ClientServerUtils.cpp.
00075 { 00076 int n; 00077 00078 again: 00079 if ( (n = accept(fd, sa, salenptr)) < 0) 00080 { 00081 if (errno == ECONNABORTED) 00082 goto again; 00083 else 00084 throw NetworkException 00085 ( (string)"accept error: " + (string)strerror(errno) ); 00086 } 00087 return(n); 00088 } // ~Accept
| void Bind | ( | int | fd, | |
| const sockaddr * | sa, | |||
| socklen_t | salen | |||
| ) |
| void Close | ( | int | fd | ) |
Definition at line 144 of file ClientServerUtils.cpp.
Referenced by main(), and threadWrapper().
00145 { 00146 if (close(fd) == -1) 00147 { 00148 throw NetworkException 00149 ( (string)"close error: " + (string)strerror(errno) ); 00150 } 00151 }
Here is the caller graph for this function:

| void Connect | ( | int | fd, | |
| const sockaddr * | sa, | |||
| socklen_t | salen | |||
| ) |
| void err_sys | ( | const char * | fmt, | |
| ... | ||||
| ) |
Definition at line 66 of file ClientServerUtils.cpp.
Referenced by main().
Here is the caller graph for this function:

| char* Fgets | ( | char * | ptr, | |
| int | n, | |||
| FILE * | stream | |||
| ) |
Definition at line 328 of file ClientServerUtils.cpp.
00329 { 00330 char *rptr; 00331 if ( (rptr = fgets(ptr, n, stream)) == NULL && ferror(stream)) 00332 throw NetworkException("fgets error"); 00333 return (rptr); 00334 }
| pid_t Fork | ( | void | ) |
Definition at line 154 of file ClientServerUtils.cpp.
Referenced by main().
00155 { 00156 pid_t pid; 00157 if ( (pid = fork()) == -1) throw NetworkException("fork error"); 00158 return(pid); 00159 }
Here is the caller graph for this function:

| void Fputs | ( | const char * | ptr, | |
| FILE * | stream | |||
| ) |
Definition at line 336 of file ClientServerUtils.cpp.
00337 { 00338 if (fputs(ptr, stream) == EOF) throw NetworkException("fputs error"); 00339 }
| void Listen | ( | int | fd, | |
| int | backlog | |||
| ) |
Definition at line 99 of file ClientServerUtils.cpp.
Referenced by main().
00100 { 00101 char *ptr; 00102 00103 /*4can override 2nd argument with environment variable */ 00104 if ( (ptr = getenv("LISTENQ")) != NULL) 00105 backlog = atoi(ptr); 00106 00107 if (listen(fd, backlog) < 0) 00108 throw NetworkException 00109 ( (string)"listen error: " + (string)strerror(errno) ); 00110 } // ~Listen
Here is the caller graph for this function:

| ssize_t Readn | ( | int | fd, | |
| void * | ptr, | |||
| size_t | nbytes | |||
| ) |
Definition at line 196 of file ClientServerUtils.cpp.
References readn().
00197 { 00198 ssize_t n; 00199 00200 if ( (n = readn(fd, ptr, nbytes)) < 0) 00201 throw NetworkException("readn error"); 00202 return(n); 00203 }
Here is the call graph for this function:

| ssize_t readn | ( | int | fd, | |
| void * | vptr, | |||
| size_t | n | |||
| ) |
Definition at line 169 of file ClientServerUtils.cpp.
Referenced by Readn().
00171 { 00172 size_t nleft; 00173 ssize_t nread; 00174 char *ptr; 00175 00176 ptr = (char*) vptr; 00177 nleft = n; 00178 while (nleft > 0) 00179 { 00180 if ( (nread = read(fd, ptr, nleft)) < 0) 00181 { 00182 if (errno == EINTR) 00183 nread = 0; /* and call read() again */ 00184 else 00185 return(-1); 00186 } else if (nread == 0) 00187 break; /* EOF */ 00188 00189 nleft -= nread; 00190 ptr += nread; 00191 } 00192 return(n - nleft); /* return >= 0 */ 00193 }
Here is the caller graph for this function:

| void sig_chld | ( | int | signo | ) |
Definition at line 107 of file SSAHAServer.cpp.
References myPID.
Referenced by main().
00108 { 00109 pid_t pid; 00110 int stat; 00111 00112 while ( (pid = waitpid(-1, &stat, WNOHANG)) > 0) 00113 cout << myPID << ": terminated child " << pid << endl; 00114 // printf("child %d terminated\n", pid); 00115 return; 00116 }
Here is the caller graph for this function:

Definition at line 134 of file ClientServerUtils.cpp.
References signal().
Referenced by main().
00135 { 00136 Sigfunc *sigfunc; 00137 if ( (sigfunc = signal(signo, func)) == SIG_ERR) 00138 throw NetworkException 00139 ( (string)"signal error: " + (string)strerror(errno) ); 00140 return(sigfunc); 00141 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 112 of file ClientServerUtils.cpp.
Referenced by Signal().
00113 { 00114 struct sigaction act, oact; 00115 00116 act.sa_handler = func; 00117 sigemptyset(&act.sa_mask); 00118 act.sa_flags = 0; 00119 if (signo == SIGALRM) { 00120 #ifdef SA_INTERRUPT 00121 act.sa_flags |= SA_INTERRUPT; /* SunOS 4.x */ 00122 #endif 00123 } else { 00124 #ifdef SA_RESTART 00125 act.sa_flags |= SA_RESTART; /* SVR4, 44BSD */ 00126 #endif 00127 } 00128 if (sigaction(signo, &act, &oact) < 0) 00129 return(SIG_ERR); 00130 return(oact.sa_handler); 00131 }
Here is the caller graph for this function:

| int Socket | ( | int | family, | |
| int | type, | |||
| int | protocol | |||
| ) |
Definition at line 161 of file ClientServerUtils.cpp.
Referenced by main().
00162 { 00163 int n; 00164 if ( (n = socket(family, type, protocol)) < 0) throw NetworkException("socket error"); 00165 return(n); 00166 }
Here is the caller graph for this function:

| void Writen | ( | int | fd, | |
| void * | ptr, | |||
| size_t | nbytes | |||
| ) |
Definition at line 315 of file ClientServerUtils.cpp.
References writen().
Referenced by SocketInterface::sendChars(), SocketInterface::sendSequence(), SocketInterface::sendString(), and SocketInterface::sendStruct().
00316 { 00317 00318 00319 if (writen(fd, ptr, nbytes) != nbytes) 00320 { 00321 // cout << "Error no :"<< errno << endl; 00322 throw BrokenSocketException(); 00323 // else throw NetworkException("writen error"); 00324 } 00325 }
Here is the call graph for this function:

Here is the caller graph for this function:

| ssize_t writen | ( | int | fd, | |
| const void * | vptr, | |||
| size_t | n | |||
| ) |
Definition at line 270 of file ClientServerUtils.cpp.
Referenced by Writen().
00272 { 00273 size_t nleft; 00274 ssize_t nwritten; 00275 const char *ptr; 00276 00277 // pollfd pollDetails; 00278 // pollDetails.fd=fd; 00279 // pollDetails.events=POLLIN|POLLRDNORM|POLLRDBAND|POLLPRI|POLLOUT|POLLWRNORM|POLLWRBAND; 00280 // int pollOut(0); 00281 00282 00283 ptr = (char *) vptr; 00284 nleft = n; 00285 while (nleft > 0) { 00286 00287 // do { pollOut=poll(&pollDetails,1,10); } while (pollOut==0); 00288 // cout << "POLL Writen: " << pollOut 00289 // << ((pollDetails.revents|POLLIN!=0)?'1':'0') 00290 // << ((pollDetails.revents|POLLRDNORM!=0)?'1':'0') 00291 // << ((pollDetails.revents|POLLRDBAND!=0)?'1':'0') 00292 // << ((pollDetails.revents|POLLPRI!=0)?'1':'0') 00293 // << ((pollDetails.revents|POLLOUT!=0)?'1':'0') 00294 // << ((pollDetails.revents|POLLWRNORM!=0)?'1':'0') 00295 // << ((pollDetails.revents|POLLWRBAND!=0)?'1':'0') 00296 // << ((pollDetails.revents|POLLERR!=0)?'1':'0') 00297 // << ((pollDetails.revents|POLLHUP!=0)?'1':'0') 00298 // << ((pollDetails.revents|POLLNVAL!=0)?'1':'0') << endl; 00299 00300 00301 if ( (nwritten = write(fd, ptr, nleft)) <= 0) { 00302 if (errno == EINTR) 00303 nwritten = 0; /* and call write() again */ 00304 else 00305 return(-1); /* error */ 00306 } 00307 00308 nleft -= nwritten; 00309 ptr += nwritten; 00310 } 00311 return(n); 00312 }
Here is the caller graph for this function:

| struct MatchHeader packed |
| struct SequenceHeader packed |
| struct QueryHeader packed |
1.5.2