comparison src/client.c @ 157:976ff791c7ec noffle

[svn] Extract common code from putCmd and putCmdNoFlush, reset client.lastStat when sending new command.
author enz
date Sun, 10 Dec 2000 11:34:50 +0000
parents 8b9366fc1361
children 94f2e5607772
comparison
equal deleted inserted replaced
156:a7882c8e180c 157:976ff791c7ec
1 /* 1 /*
2 client.c 2 client.c
3 3
4 $Id: client.c 217 2000-09-23 10:40:35Z enz $ 4 $Id: client.c 240 2000-12-10 11:34:50Z enz $
5 */ 5 */
6 6
7 #if HAVE_CONFIG_H 7 #if HAVE_CONFIG_H
8 #include <config.h> 8 #include <config.h>
9 #endif 9 #endif
119 fflush( client.out ); 119 fflush( client.out );
120 Log_dbg( "[S FLUSH]" ); 120 Log_dbg( "[S FLUSH]" );
121 } 121 }
122 122
123 static Bool 123 static Bool
124 putCmd( const char *fmt, ... ) 124 putCmdLn( const char *line )
125 { 125 {
126 Bool err; 126 Bool err;
127 unsigned int n; 127 unsigned int n;
128 Str line; 128
129 va_list ap;
130
131 va_start( ap, fmt );
132 vsnprintf( line, MAXCHAR, fmt, ap );
133 va_end( ap );
134 strcpy( client.lastCmd, line ); 129 strcpy( client.lastCmd, line );
135 Log_dbg( "[S] %s", line ); 130 strcpy( client.lastStat, "[no status available]" );
136 n = fprintf( client.out, "%s\r\n", line );
137 fflush( client.out );
138 Log_dbg( "[S FLUSH]" );
139 err = ( n != strlen( line ) + 2 );
140 if ( err )
141 logBreakDown();;
142 return ! err;
143 }
144
145 static Bool
146 putCmdNoFlush( const char *fmt, ... )
147 {
148 Bool err;
149 unsigned int n;
150 Str line;
151 va_list ap;
152
153 va_start( ap, fmt );
154 vsnprintf( line, MAXCHAR, fmt, ap );
155 va_end( ap );
156 strcpy( client.lastCmd, line );
157 Log_dbg( "[S] %s", line ); 131 Log_dbg( "[S] %s", line );
158 n = fprintf( client.out, "%s\r\n", line ); 132 n = fprintf( client.out, "%s\r\n", line );
159 err = ( n != strlen( line ) + 2 ); 133 err = ( n != strlen( line ) + 2 );
160 if ( err ) 134 if ( err )
161 logBreakDown();; 135 logBreakDown();;
162 return ! err; 136 return ! err;
137 }
138
139 static Bool
140 putCmd( const char *fmt, ... )
141 {
142 Str line;
143 va_list ap;
144
145 va_start( ap, fmt );
146 vsnprintf( line, MAXCHAR, fmt, ap );
147 va_end( ap );
148 if ( ! putCmdLn( line ) )
149 return FALSE;
150 fflush( client.out );
151 Log_dbg( "[S FLUSH]" );
152 return TRUE;
153 }
154
155 static Bool
156 putCmdNoFlush( const char *fmt, ... )
157 {
158 Str line;
159 va_list ap;
160
161 va_start( ap, fmt );
162 vsnprintf( line, MAXCHAR, fmt, ap );
163 va_end( ap );
164 return putCmdLn( line );
163 } 165 }
164 166
165 static int getStat( void ); 167 static int getStat( void );
166 168
167 static Bool 169 static Bool