mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-01 11:32:48 -05:00
Use the BinarySink system for conf serialisation.
Now instead of iterating through conf twice in separate functions, once to count up the size of the serialised data and once to write it out, I just go through once and dump it all in a strbuf. (Of course, I could still do a two-pass count-then-allocate approach easily enough in this system; nothing would stop me writing a BinarySink implementation that didn't actually store any data and just counted its size, and then I could choose at each call site whether I preferred to do it that way.)
This commit is contained in:
@ -156,8 +156,8 @@ void launch_duplicate_session(Conf *conf)
|
||||
* into a byte stream, create a pipe, and send this byte stream
|
||||
* to the child through the pipe.
|
||||
*/
|
||||
int i, ret, sersize, size;
|
||||
char *data;
|
||||
int i, ret;
|
||||
strbuf *serialised;
|
||||
char option[80];
|
||||
int pipefd[2];
|
||||
|
||||
@ -166,35 +166,27 @@ void launch_duplicate_session(Conf *conf)
|
||||
return;
|
||||
}
|
||||
|
||||
size = sersize = conf_serialised_size(conf);
|
||||
if (use_pty_argv && pty_argv) {
|
||||
serialised = strbuf_new();
|
||||
|
||||
conf_serialise(BinarySink_UPCAST(serialised), conf);
|
||||
if (use_pty_argv && pty_argv)
|
||||
for (i = 0; pty_argv[i]; i++)
|
||||
size += strlen(pty_argv[i]) + 1;
|
||||
}
|
||||
put_asciz(serialised, pty_argv[i]);
|
||||
|
||||
data = snewn(size, char);
|
||||
conf_serialise(conf, data);
|
||||
if (use_pty_argv && pty_argv) {
|
||||
int p = sersize;
|
||||
for (i = 0; pty_argv[i]; i++) {
|
||||
strcpy(data + p, pty_argv[i]);
|
||||
p += strlen(pty_argv[i]) + 1;
|
||||
}
|
||||
assert(p == size);
|
||||
}
|
||||
|
||||
sprintf(option, "---[%d,%d]", pipefd[0], size);
|
||||
sprintf(option, "---[%d,%d]", pipefd[0], serialised->len);
|
||||
noncloexec(pipefd[0]);
|
||||
fork_and_exec_self(pipefd[1], option, NULL);
|
||||
close(pipefd[0]);
|
||||
|
||||
i = ret = 0;
|
||||
while (i < size && (ret = write(pipefd[1], data + i, size - i)) > 0)
|
||||
while (i < serialised->len &&
|
||||
(ret = write(pipefd[1], serialised->s + i,
|
||||
serialised->len - i)) > 0)
|
||||
i += ret;
|
||||
if (ret < 0)
|
||||
perror("write to pipe");
|
||||
close(pipefd[1]);
|
||||
sfree(data);
|
||||
strbuf_free(serialised);
|
||||
}
|
||||
|
||||
void launch_new_session(void)
|
||||
|
@ -74,14 +74,9 @@ void filename_free(Filename *fn)
|
||||
sfree(fn);
|
||||
}
|
||||
|
||||
int filename_serialise(const Filename *f, void *vdata)
|
||||
void filename_serialise(BinarySink *bs, const Filename *f)
|
||||
{
|
||||
char *data = (char *)vdata;
|
||||
int len = strlen(f->path) + 1; /* include trailing NUL */
|
||||
if (data) {
|
||||
strcpy(data, f->path);
|
||||
}
|
||||
return len;
|
||||
put_asciz(bs, f->path);
|
||||
}
|
||||
Filename *filename_deserialise(void *vdata, int maxsize, int *used)
|
||||
{
|
||||
@ -275,12 +270,9 @@ void fontspec_free(FontSpec *f)
|
||||
sfree(f->name);
|
||||
sfree(f);
|
||||
}
|
||||
int fontspec_serialise(FontSpec *f, void *data)
|
||||
void fontspec_serialise(BinarySink *bs, FontSpec *f)
|
||||
{
|
||||
int len = strlen(f->name);
|
||||
if (data)
|
||||
strcpy(data, f->name);
|
||||
return len + 1; /* include trailing NUL */
|
||||
put_asciz(bs, f->name);
|
||||
}
|
||||
FontSpec *fontspec_deserialise(void *vdata, int maxsize, int *used)
|
||||
{
|
||||
|
Reference in New Issue
Block a user