⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plserver.c

📁 了解服务器的内部结构
💻 C
📖 第 1 页 / 共 2 页
字号:

connection = packet->phd_connection;
packet->phd_type = PL_REPLY;
reply (connection, packet, sizeof (struct phd), NULL, 0);

/* Get rid of file segments */

while (connection->plc_attachments)
    detach (connection->plc_attachments);

/* Get rid of connection block */

for (ptr = &connections; *ptr; ptr = &(*ptr)->plc_next)
    if (*ptr == connection)
	{
	*ptr = connection->plc_next;
	break;
	}
}

static void ipc_error (
    status_$t	status,
    UCHAR	*string)
{
/**************************************
 *
 *	i p c _ e r r o r
 *
 **************************************
 *
 * Functional description
 *	A more or less fatal error occurred.  Seppicu time.
 *
 **************************************/

ib_fprintf (ib_stderr, "Error during %s operation\n", string);
error_$print (status);
abort();
}

static UCHAR *map_file (
    PLC		connection,
    FIL		file,
    ULONG	offset)
{
/**************************************
 *
 *	m a p _ f i l e
 *
 **************************************
 *
 * Functional description
 *	Map a page in a file.
 *
 **************************************/
FWIN		*window, *win, *end;
SLONG		section;
status_$t	status;
USHORT		i, length;
UCHAR		*address;

win = NULL;

/* Search for a window that is already mapped. */

for (window = file->fil_windows, end = window + file->fil_count;
     window < end; window++)
    {
    if (offset >= window->fwin_offset && 
	offset < window->fwin_offset + window->fwin_length)
	goto exit;
    if (!win || window->fwin_activity < win->fwin_activity)
	win = window;
    }

/* If not all windows have been used, use another */

section = offset &~ (WINDOW_LENGTH - 1);

if (file->fil_count < WINDOWS)
    {
    address = ms_$mapl (file->fil_name, file->fil_length, section, 
	    (SLONG) WINDOW_LENGTH, ms_$cowriters, ms_$wr, (SSHORT) -1,
	    window->fwin_length, status);

    if (status.all)
	return client_error (connection, "ms_$mapl", status);
    ++file->fil_count;
    goto finish;
    }

/* Window not found, remap it.  */

window = win;
address= ms_$remap (window->fwin_address, section, 
	(SLONG) WINDOW_LENGTH, window->fwin_length, status);

if (status.all)
    return client_error (connection, "ms_$remap", status);

/* Down grade activity after window shift */

for (win = file->fil_windows; win < end; win++)
    win->fwin_activity >>= 2;

finish:

window->fwin_address = address;
window->fwin_offset = section;
window->fwin_activity = 0;

exit:

++window->fwin_activity;
return (SCHAR*) window->fwin_address + offset - window->fwin_offset;
}


static void move (
    UCHAR	*from,
    UCHAR	*to,
    USHORT	length)
{
/**************************************
 *
 *	m o v e
 *
 **************************************
 *
 * Functional description
 *	Move a fixed length string.
 *
 **************************************/

if (length)
    do *to++ = *from++; while (--length);
}

static void open (
    PHD		*packet,
    UCHAR	*data)
{
/**************************************
 *
 *	o p e n
 *
 **************************************
 *
 * Functional description
 *	Open a file.
 *
 **************************************/
PLC		connection;
FIL		file;
FAT		attachment;
FWIN		*window;
status_$t	status;

data [packet->phd_length] = 0;
connection = packet->phd_connection;

/* Check to see if file is already known */

for (file = files; file; file = file->fil_next)
    if (!strcmp (data, file->fil_name))
	break;

/* If file doesn't exist, create it now */

if (!file)
    {
    file = alloc (sizeof (struct fil) + packet->phd_length);
    file->fil_length = packet->phd_length;
    strcpy (file->fil_name, data);
    file->fil_next = files;
    files = file;
    file->fil_count = 1;

    /* Map the file as appropriate */

    window = file->fil_windows;
    window->fwin_address = ms_$mapl (file->fil_name, file->fil_length, 
	window->fwin_offset, (SLONG) WINDOW_LENGTH, 
	ms_$cowriters, ms_$wr, (SSHORT) -1,
	window->fwin_length, status);
    if (status.all)
	client_error (connection, "ms_$mapl", status);
    file->fil_count = 1;
    }

/* Connect file and connection block */

attachment = alloc (sizeof (struct fat));
attachment->fat_connection = connection;
attachment->fat_file = file;
attachment->fat_next_file = file->fil_attachments;
file->fil_attachments = attachment;
attachment->fat_next_connection = connection->plc_attachments;
connection->plc_attachments = attachment;

/* Send a reply */

packet->phd_handle = attachment;
packet->phd_type = PL_REPLY;
reply (connection, packet, sizeof (struct phd), NULL, 0);
}

static void page_read (
    PHD		*packet)
{
/**************************************
 *
 *	p a g e _ r e a d
 *
 **************************************
 *
 * Functional description
 *	Read a database page.
 *
 **************************************/
PLC		connection;
FIL		file;
FAT		attachment;
UCHAR		*ptr;
status_$t	status;

connection = packet->phd_connection;
attachment = packet->phd_handle;
file = attachment->fat_file;

/* Map appropriate part of file */

ptr = map_file (connection, file, packet->phd_misc);
if (ptr == -1)
    return;

/* Send a reply */

packet->phd_handle = attachment;
packet->phd_type = PL_REPLY;
reply (connection, packet, sizeof (struct phd), ptr, packet->phd_length);
}

static void page_write (
    PHD		*packet,
    UCHAR	*data)
{
/**************************************
 *
 *	p a g e _ w r i t e
 *
 **************************************
 *
 * Functional description
 *	Write a database page.
 *
 **************************************/
PLC		connection;
FIL		file;
FAT		attachment;
UCHAR		*ptr;
status_$t	status;

attachment = packet->phd_handle;
connection = packet->phd_connection;
file = attachment->fat_file;

/* Map appropriate part of file */

ptr = map_file (connection, file, packet->phd_misc);
if (ptr == -1)
    return;

move (data, ptr, packet->phd_length);

/* Send a reply */

packet->phd_handle = attachment;
packet->phd_type = PL_REPLY;
reply (connection, packet, sizeof (struct phd), NULL, 0);
}

static void release (
    UCHAR	*blk)
{
/**************************************
 *
 *	r e l e a s e
 *
 **************************************
 *
 * Functional description
 *	Release a block.
 *
 **************************************/

gds__free (blk);
}

static void reply (
    PLC		connection,
    PHD		*header,
    USHORT	header_len,
    UCHAR	*data,
    USHORT	data_len)
{
/**************************************
 *
 *	r e p l y 
 *
 **************************************
 *
 * Functional description
 *	Reply to a request.
 *
 **************************************/
status_$t	status;

BUMP_SEQUENCE (connection->plc_send_sequence);
header->phd_sequence = connection->plc_send_sequence;
header->phd_ack = connection->plc_recv_sequence;

ipc_$send (connection->plc_socket, server_handle, 
	   *header, header_len, *data, data_len, status);
if (status.all)
    ipc_error (status, "icp_$send");
}

static int socket_eql (
    UCHAR	*socket1,
    UCHAR	*socket2)
{
/**************************************
 *
 *	s o c k e t _ e q l
 *
 **************************************
 *
 * Functional description
 *	Compare two sockets for equality.
 *
 **************************************/
UCHAR	*end;

end = socket1 + sizeof (struct ipc_$socket_handle);

while (socket1 < end)
    if (*socket1++ != socket2++)
	return FALSE;

return TRUE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -