Skip to content

Commit 19ee980

Browse files
jeffhostetlerdscho
authored andcommitted
fixup! simple-ipc: preparations for supporting binary messages.
This reverts commit 15b44c3. Signed-off-by: Jeff Hostetler <[email protected]>
1 parent f3c5e26 commit 19ee980

File tree

4 files changed

+23
-46
lines changed

4 files changed

+23
-46
lines changed

compat/simple-ipc/ipc-unix-socket.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,15 @@ void ipc_client_close_connection(struct ipc_client_connection *connection)
168168

169169
int ipc_client_send_command_to_connection(
170170
struct ipc_client_connection *connection,
171-
const char *message, size_t message_len,
172-
struct strbuf *answer)
171+
const char *message, struct strbuf *answer)
173172
{
174173
int ret = 0;
175174

176175
strbuf_setlen(answer, 0);
177176

178177
trace2_region_enter("ipc-client", "send-command", NULL);
179178

180-
if (write_packetized_from_buf_no_flush(message, message_len,
179+
if (write_packetized_from_buf_no_flush(message, strlen(message),
181180
connection->fd) < 0 ||
182181
packet_flush_gently(connection->fd) < 0) {
183182
ret = error(_("could not send IPC command"));
@@ -198,8 +197,7 @@ int ipc_client_send_command_to_connection(
198197

199198
int ipc_client_send_command(const char *path,
200199
const struct ipc_client_connect_options *options,
201-
const char *message, size_t message_len,
202-
struct strbuf *answer)
200+
const char *message, struct strbuf *answer)
203201
{
204202
int ret = -1;
205203
enum ipc_active_state state;
@@ -210,9 +208,7 @@ int ipc_client_send_command(const char *path,
210208
if (state != IPC_STATE__LISTENING)
211209
return ret;
212210

213-
ret = ipc_client_send_command_to_connection(connection,
214-
message, message_len,
215-
answer);
211+
ret = ipc_client_send_command_to_connection(connection, message, answer);
216212

217213
ipc_client_close_connection(connection);
218214

@@ -507,7 +503,7 @@ static int worker_thread__do_io(
507503
if (ret >= 0) {
508504
ret = worker_thread_data->server_data->application_cb(
509505
worker_thread_data->server_data->application_data,
510-
buf.buf, buf.len, do_io_reply_callback, &reply_data);
506+
buf.buf, do_io_reply_callback, &reply_data);
511507

512508
packet_flush_gently(reply_data.fd);
513509
}

compat/simple-ipc/ipc-win32.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,15 @@ void ipc_client_close_connection(struct ipc_client_connection *connection)
208208

209209
int ipc_client_send_command_to_connection(
210210
struct ipc_client_connection *connection,
211-
const char *message, size_t message_len,
212-
struct strbuf *answer)
211+
const char *message, struct strbuf *answer)
213212
{
214213
int ret = 0;
215214

216215
strbuf_setlen(answer, 0);
217216

218217
trace2_region_enter("ipc-client", "send-command", NULL);
219218

220-
if (write_packetized_from_buf_no_flush(message, message_len,
219+
if (write_packetized_from_buf_no_flush(message, strlen(message),
221220
connection->fd) < 0 ||
222221
packet_flush_gently(connection->fd) < 0) {
223222
ret = error(_("could not send IPC command"));
@@ -240,8 +239,7 @@ int ipc_client_send_command_to_connection(
240239

241240
int ipc_client_send_command(const char *path,
242241
const struct ipc_client_connect_options *options,
243-
const char *message, size_t message_len,
244-
struct strbuf *response)
242+
const char *message, struct strbuf *response)
245243
{
246244
int ret = -1;
247245
enum ipc_active_state state;
@@ -252,9 +250,7 @@ int ipc_client_send_command(const char *path,
252250
if (state != IPC_STATE__LISTENING)
253251
return ret;
254252

255-
ret = ipc_client_send_command_to_connection(connection,
256-
message, message_len,
257-
response);
253+
ret = ipc_client_send_command_to_connection(connection, message, response);
258254

259255
ipc_client_close_connection(connection);
260256

@@ -462,7 +458,7 @@ static int do_io(struct ipc_server_thread_data *server_thread_data)
462458
if (ret >= 0) {
463459
ret = server_thread_data->server_data->application_cb(
464460
server_thread_data->server_data->application_data,
465-
buf.buf, buf.len, do_io_reply_callback, &reply_data);
461+
buf.buf, do_io_reply_callback, &reply_data);
466462

467463
packet_flush_gently(reply_data.fd);
468464

simple-ipc.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ void ipc_client_close_connection(struct ipc_client_connection *connection);
107107
*/
108108
int ipc_client_send_command_to_connection(
109109
struct ipc_client_connection *connection,
110-
const char *message, size_t message_len,
111-
struct strbuf *answer);
110+
const char *message, struct strbuf *answer);
112111

113112
/*
114113
* Used by the client to synchronously connect and send and receive a
@@ -120,8 +119,7 @@ int ipc_client_send_command_to_connection(
120119
*/
121120
int ipc_client_send_command(const char *path,
122121
const struct ipc_client_connect_options *options,
123-
const char *message, size_t message_len,
124-
struct strbuf *answer);
122+
const char *message, struct strbuf *answer);
125123

126124
/*
127125
* Simple IPC Server Side API.
@@ -146,7 +144,6 @@ typedef int (ipc_server_reply_cb)(struct ipc_server_reply_data *,
146144
*/
147145
typedef int (ipc_server_application_cb)(void *application_data,
148146
const char *request,
149-
size_t request_len,
150147
ipc_server_reply_cb *reply_cb,
151148
struct ipc_server_reply_data *reply_data);
152149

t/helper/test-simple-ipc.c

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static int app__slow_command(ipc_server_reply_cb *reply_cb,
112112
/*
113113
* The client sent a command followed by a (possibly very) large buffer.
114114
*/
115-
static int app__sendbytes_command(const char *received, size_t received_len,
115+
static int app__sendbytes_command(const char *received,
116116
ipc_server_reply_cb *reply_cb,
117117
struct ipc_server_reply_data *reply_data)
118118
{
@@ -123,13 +123,6 @@ static int app__sendbytes_command(const char *received, size_t received_len,
123123
int errs = 0;
124124
int ret;
125125

126-
/*
127-
* The test is setup to send:
128-
* "sendbytes" SP <n * char>
129-
*/
130-
if (received_len < strlen("sendbytes "))
131-
BUG("received_len is short in app__sendbytes_command");
132-
133126
if (skip_prefix(received, "sendbytes ", &p))
134127
len_ballast = strlen(p);
135128

@@ -167,7 +160,7 @@ static ipc_server_application_cb test_app_cb;
167160
* by this application.
168161
*/
169162
static int test_app_cb(void *application_data,
170-
const char *command, size_t command_len,
163+
const char *command,
171164
ipc_server_reply_cb *reply_cb,
172165
struct ipc_server_reply_data *reply_data)
173166
{
@@ -180,7 +173,7 @@ static int test_app_cb(void *application_data,
180173
if (application_data != (void*)&my_app_data)
181174
BUG("application_cb: application_data pointer wrong");
182175

183-
if (command_len == 4 && !strncmp(command, "quit", 4)) {
176+
if (!strcmp(command, "quit")) {
184177
/*
185178
* The client sent a "quit" command. This is an async
186179
* request for the server to shutdown.
@@ -200,23 +193,22 @@ static int test_app_cb(void *application_data,
200193
return SIMPLE_IPC_QUIT;
201194
}
202195

203-
if (command_len == 4 && !strncmp(command, "ping", 4)) {
196+
if (!strcmp(command, "ping")) {
204197
const char *answer = "pong";
205198
return reply_cb(reply_data, answer, strlen(answer));
206199
}
207200

208-
if (command_len == 3 && !strncmp(command, "big", 3))
201+
if (!strcmp(command, "big"))
209202
return app__big_command(reply_cb, reply_data);
210203

211-
if (command_len == 5 && !strncmp(command, "chunk", 5))
204+
if (!strcmp(command, "chunk"))
212205
return app__chunk_command(reply_cb, reply_data);
213206

214-
if (command_len == 4 && !strncmp(command, "slow", 4))
207+
if (!strcmp(command, "slow"))
215208
return app__slow_command(reply_cb, reply_data);
216209

217-
if (command_len >= 10 && starts_with(command, "sendbytes "))
218-
return app__sendbytes_command(command, command_len,
219-
reply_cb, reply_data);
210+
if (starts_with(command, "sendbytes "))
211+
return app__sendbytes_command(command, reply_cb, reply_data);
220212

221213
return app__unhandled_command(command, reply_cb, reply_data);
222214
}
@@ -496,9 +488,7 @@ static int client__send_ipc(void)
496488
options.wait_if_busy = 1;
497489
options.wait_if_not_found = 0;
498490

499-
if (!ipc_client_send_command(cl_args.path, &options,
500-
command, strlen(command),
501-
&buf)) {
491+
if (!ipc_client_send_command(cl_args.path, &options, command, &buf)) {
502492
if (buf.len) {
503493
printf("%s\n", buf.buf);
504494
fflush(stdout);
@@ -566,9 +556,7 @@ static int do_sendbytes(int bytecount, char byte, const char *path,
566556
strbuf_addstr(&buf_send, "sendbytes ");
567557
strbuf_addchars(&buf_send, byte, bytecount);
568558

569-
if (!ipc_client_send_command(path, options,
570-
buf_send.buf, buf_send.len,
571-
&buf_resp)) {
559+
if (!ipc_client_send_command(path, options, buf_send.buf, &buf_resp)) {
572560
strbuf_rtrim(&buf_resp);
573561
printf("sent:%c%08d %s\n", byte, bytecount, buf_resp.buf);
574562
fflush(stdout);

0 commit comments

Comments
 (0)