This commit is contained in:
parth21999 2020-07-08 19:34:27 -04:00
Родитель 4dcab5593e
Коммит 41be368dbc
25 изменённых файлов: 163 добавлений и 695 удалений

2
.gitignore поставляемый
Просмотреть файл

@ -53,3 +53,5 @@ dkms.conf
cmake*/
.vscode/
win32/tests/scratch_ut

Просмотреть файл

@ -1,13 +1,17 @@
#Copyright (C) Microsoft Corporation. All rights reserved.
set(pal_common_h_files
inc/gballoc.h
../common/inc/gballoc.h
../common/inc/constbuffer.h
../common/inc/buffer_.h
PARENT_SCOPE
)
set(pal_common_c_files
src/gballoc.c
src/constbuffer.c
src/buffer.c
../common/src/gballoc.c
../common/src/constbuffer.c
../common/src/buffer.c
PARENT_SCOPE
)
FILE(GLOB pal_common_md_files "devdoc/*.md")
@ -15,9 +19,9 @@ SOURCE_GROUP(devdoc FILES ${pal_common_md_files})
include_directories(${CMAKE_CURRENT_LIST_DIR}/inc)
add_library(pal_common ${pal_common_h_files} ${pal_common_c_files} ${pal_common_md_files})
target_link_libraries(pal_common pal_interfaces azure_c_logging)
target_include_directories(pal_common PUBLIC ${CMAKE_CURRENT_LIST_DIR}/inc)
#add_library(pal_common ${pal_common_h_files} ${pal_common_c_files} ${pal_common_md_files})
#target_link_libraries(pal_common pal_interfaces azure_c_logging)
#target_include_directories(pal_common PUBLIC ${CMAKE_CURRENT_LIST_DIR}/inc)
add_subdirectory(tests)
#add_subdirectory(tests)

Просмотреть файл

@ -16,8 +16,6 @@ set(pal_interfaces_h_files
inc/string_utils.h
inc/sync.h
inc/file.h
inc/constbuffer.h
inc/buffer_.h
inc/refcount.h
)

Просмотреть файл

@ -1,248 +0,0 @@
BUFFER Requirements
================
## Overview
The BUFFER object encapsulastes a unsigned char* variable.
## Exposed API
```c
typedef void* BUFFER_HANDLE;
extern BUFFER_HANDLE BUFFER_new(void);
extern void BUFFER_delete(BUFFER_HANDLE handle);
extern BUFFER_HANDLE BUFFER_create(const unsigned char* source, size_t size);
extern BUFFER_HANDLE BUFFER_create_with_size(size_t buff_size)
extern int BUFFER_pre_build(BUFFER_HANDLE handle, size_t size);
extern int BUFFER_build(BUFFER_HANDLE handle, const unsigned char* source, size_t size);
extern int BUFFER_unbuild(BUFFER_HANDLE handle);
extern int BUFFER_enlarge(BUFFER_HANDLE handle, size_t enlargeSize);
extern int BUFFER_content(BUFFER_HANDLE handle, const unsigned char** content);
extern int BUFFER_size(BUFFER_HANDLE handle, size_t* size);
extern int BUFFER_append(BUFFER_HANDLE handle1, BUFFER_HANDLE handle2);
extern int BUFFER_prepend(BUFFER_HANDLE handle1, BUFFER_HANDLE handle2);
extern unsigned char* BUFFER_u_char(BUFFER_HANDLE handle);
extern size_t BUFFER_length(BUFFER_HANDLE handle);
extern BUFFER_HANDLE BUFFER_clone(BUFFER_HANDLE handle);
extern int BUFFER_fill(BUFFER_HANDLE handle, unsigned char fill_char);
```
### BUFFER_new
```c
BUFFER_HANDLE BUFFER_new(void)
```
**SRS_BUFFER_07_001: [** BUFFER_new shall allocate a BUFFER_HANDLE that will contain a NULL unsigned char*. **]**
### BUFFER_create
```c
extern BUFFER_HANDLE BUFFER_create(const unsigned char* source, size_t size);
```
BUFFER_create creates a new buffer from the memory at source, having size "size".
**SRS_BUFFER_02_001: [** If source is NULL then BUFFER_create shall return NULL. **]**
**SRS_BUFFER_02_002: [** Otherwise, BUFFER_create shall allocate memory to hold size bytes and shall copy from source size bytes into the newly allocated memory. **]**
**SRS_BUFFER_02_005: [** If size parameter is 0 then 1 byte of memory shall be allocated yet size of the buffer shall be set to 0. **]**
**SRS_BUFFER_02_003: [** If allocating memory fails, then BUFFER_create shall return NULL. **]**
**SRS_BUFFER_02_004: [** Otherwise, BUFFER_create shall return a non-NULL handle. **]**
### BUFFER_create_with_size
```c
extern BUFFER_HANDLE BUFFER_create_with_size(size_t buff_size)
```
**SRS_BUFFER_07_029: [** BUFFER_create_with_size shall create a BUFFER_HANDLE with a pre allocated underlying buffer size. **]**
**SRS_BUFFER_07_030: [** If buff_size is 0 BUFFER_create_with_size shall create a valid non-NULL handle of zero size. **]**
**SRS_BUFFER_07_031: [** BUFFER_create_with_size shall allocate a buffer of buff_size. **]**
**SRS_BUFFER_07_032: [** If allocating memory fails, then BUFFER_create_with_size shall return NULL. **]**
**SRS_BUFFER_07_033: [** Otherwise, BUFFER_create_with_size shall return a non-NULL handle. **]**
### BUFFER_delete
```c
void BUFFER_delete(BUFFER_HANDLE handle)
```
**SRS_BUFFER_07_003: [** BUFFER_delete shall delete the data associated with the BUFFER_HANDLE along with the Buffer. **]**
**SRS_BUFFER_07_004: [** BUFFER_delete shall not delete any BUFFER_HANDLE that is NULL. **]**
### BUFFER_pre_build
```c
int BUFFER_pre_build(BUFFER_HANDLE handle, size_t size)
```
**SRS_BUFFER_07_005: [** BUFFER_pre_build allocates size_t bytes of BUFFER_HANDLE and returns zero on success. **]**
**SRS_BUFFER_07_006: [** If handle is NULL or size is 0 then BUFFER_pre_build shall return a nonzero value. **]**
**SRS_BUFFER_07_007: [** BUFFER_pre_build shall return nonzero if the buffer has been previously allocated and is not NULL. **]**
**SRS_BUFFER_07_013: [** BUFFER_pre_build shall return nonzero if any error is encountered. **]**
### BUFFER_build
```c
int BUFFER_build(BUFFER_HANDLE handle, const unsigned char* source, size_t size)
```
**SRS_BUFFER_07_008: [** BUFFER_build allocates size_t bytes, copies the unsigned char* into the buffer and returns zero on success. **]**
**SRS_BUFFER_07_009: [** BUFFER_build shall return nonzero if handle is NULL **]**
**SRS_BUFFER_01_001: [** If size is positive and source is NULL, BUFFER_build shall return nonzero **]**
**SRS_BUFFER_01_002: [** The size argument can be zero, in which case the underlying buffer held by the buffer instance shall be freed. **]**
**SRS_BUFFER_01_003: [** If size is zero, source can be NULL. **]**
**SRS_BUFFER_07_010: [** BUFFER_build shall return nonzero if any error is encountered. **]**
**SRS_BUFFER_07_011: [** BUFFER_build shall overwrite previous contents if the buffer has been previously allocated. **]**
### BUFFER_append_build
```c
int BUFFER_append_build(BUFFER_HANDLE handle, const unsigned char* source, size_t size)
```
**SRS_BUFFER_01_006: [** `BUFFER_append_build` shall return nonzero if handle or source are NULL or if size is 0. **]**
**SRS_BUFFER_01_007: [** if handle->buffer is NULL `BUFFER_append_build` shall allocate the a buffer of size bytes... **]**
**SRS_BUFFER_01_008: [** ... and copy the contents of source to handle->buffer. **]**
**SRS_BUFFER_01_009: [** if handle->buffer is not NULL `BUFFER_append_build` shall realloc the buffer to be the handle->size + size **]**
**SRS_BUFFER_01_010: [** ... and copy the contents of source to the end of the buffer. **]**
**SRS_BUFFER_07_034: [** On success `BUFFER_append_build` shall return 0 **]**
**SRS_BUFFER_07_035: [** If any error is encountered `BUFFER_append_build` shall return a non-null value. **]**
### BUFFER_unbuild
```c
int BUFFER_unbuild(BUFFER_HANDLE b)
```
**SRS_BUFFER_07_012: [** BUFFER_unbuild shall clear the underlying unsigned char* data associated with the BUFFER_HANDLE this will return zero on success. **]**
**SRS_BUFFER_07_014: [** BUFFER_unbuild shall return a nonzero value if BUFFER_HANDLE is NULL. **]**
**SRS_BUFFER_07_015: [** BUFFER_unbuild shall always return success if the unsigned char* referenced by BUFFER_HANDLE is NULL. **]**
### BUFFER_enlarge
```c
int BUFFER_enlarge(BUFFER_HANDLE handle, size_t enlargeSize)
```
**SRS_BUFFER_07_016: [** BUFFER_enlarge shall increase the size of the unsigned char* referenced by BUFFER_HANDLE. **]**
**SRS_BUFFER_07_017: [** BUFFER_enlarge shall return a nonzero result if any parameters are NULL or zero. **]**
**SRS_BUFFER_07_018: [** BUFFER_enlarge shall return a nonzero result if any error is encountered. **]**
### BUFFER_shrink
```c
int BUFFER_shrink(BUFFER_HANDLE handle, size_t decreaseSize, bool fromEnd)
```
**SRS_BUFFER_07_036: [** if handle is NULL, `BUFFER_shrink` shall return a non-null value **]**
**SRS_BUFFER_07_037: [** If decreaseSize is equal zero, `BUFFER_shrink` shall return a non-null value **]**
**SRS_BUFFER_07_038: [** If decreaseSize is less than the size of the buffer, `BUFFER_shrink` shall return a non-null value **]**
**SRS_BUFFER_07_039: [** `BUFFER_shrink` shall allocate a temporary buffer of existing buffer size minus decreaseSize. **]**
**SRS_BUFFER_07_040: [** if the fromEnd variable is true, `BUFFER_shrink` shall remove the end of the buffer of size decreaseSize. **]**
**SRS_BUFFER_07_041: [** if the fromEnd variable is false, `BUFFER_shrink` shall remove the beginning of the buffer of size decreaseSize. **]**
**SRS_BUFFER_07_042: [** If a failure is encountered, `BUFFER_shrink` shall return a non-null value **]**
**SRS_BUFFER_07_043: [** If the decreaseSize is equal the buffer size , `BUFFER_shrink` shall deallocate the buffer and set the size to zero. **]**
### BUFFER_content
```c
int BUFFER_content(BUFFER_HANDLE handle, unsigned char** content)
```
**SRS_BUFFER_07_019: [** BUFFER_content shall return the data contained within the BUFFER_HANDLE. **]**
**SRS_BUFFER_07_020: [** If the handle and/or content*is NULL BUFFER_content shall return nonzero. **]**
### BUFFER_size
```c
int BUFFER_size(BUFFER_HANDLE b, size_t* size)
```
**SRS_BUFFER_07_021: [** BUFFER_size shall place the size of the associated buffer in the size variable and return zero on success. **]**
**SRS_BUFFER_07_022: [** BUFFER_size shall return a nonzero value for any error that is encountered. **]**
### BUFFER_append
```c
int BUFFER_append(BUFFER_HANDLE handle1, BUFFER_HANDLE handle2)
```
**SRS_BUFFER_07_024: [** BUFFER_append concatenates b2 onto b1 without modifying b2 and shall return zero on success. **]**
**SRS_BUFFER_07_023: [** BUFFER_append shall return a nonzero upon any error that is encountered. **]**
### BUFFER_prepend
```c
int BUFFER_prepend(BUFFER_HANDLE handle1, BUFFER_HANDLE handle2)
```
**SRS_BUFFER_01_004: [** BUFFER_prepend concatenates handle1 onto handle2 without modifying handle1 and shall return zero on success. **]**
**SRS_BUFFER_01_005: [** BUFFER_prepend shall return a non-zero upon value any error that is encountered. **]**
### BUFFER_fill
```c
extern int BUFFER_fill(BUFFER_HANDLE handle, unsigned char fill_char);
```
**SRS_BUFFER_01_011: [** `BUFFER_fill` shall fill the supplied `BUFFER_HANDLE` with the supplied fill character. **]**
**SRS_BUFFER_07_002: [** If `handle` is NULL `BUFFER_fill` shall return a non-zero value. **]**
### BUFFER_u_char
```c
unsigned char* BUFFER_u_char(BUFFER_HANDLE handle)
```
**SRS_BUFFER_07_025: [** BUFFER_u_char shall return a pointer to the underlying unsigned char*. **]**
**SRS_BUFFER_07_026: [** BUFFER_u_char shall return NULL for any error that is encountered. **]**
### BUFFER_length
```c
size_t BUFFER_length(BUFFER_HANDLE handle)
```
**SRS_BUFFER_07_027: [** BUFFER_length shall return the size of the underlying buffer. **]**
**SRS_BUFFER_07_028: [** BUFFER_length shall return zero for any error that is encountered. **]**

Просмотреть файл

@ -1,221 +0,0 @@
ConstBuffer Requirements
================
## Overview
ConstBuffer is a module that implements a read-only buffer of bytes (unsigned char).
Once created, the buffer can no longer be changed. The buffer is ref counted so further API calls result in zero copy.
## References
[refcount](../inc/refcount.h)
[buffer](buffer_requirements.md)
## Exposed API
```c
/*this is the handle*/
typedef struct CONSTBUFFER_HANDLE_DATA_TAG* CONSTBUFFER_HANDLE;
/*this is what is returned when the content of the buffer needs access*/
typedef struct CONSTBUFFER_TAG
{
const unsigned char* buffer;
size_t size;
} CONSTBUFFER;
typedef void(*CONSTBUFFER_CUSTOM_FREE_FUNC)(void* context);
MOCKABLE_INTERFACE(constbuffer,
/*this creates a new constbuffer from a memory area*/
FUNCTION(, CONSTBUFFER_HANDLE, CONSTBUFFER_Create, const unsigned char*, source, size_t, size),
/*this creates a new constbuffer from an existing BUFFER_HANDLE*/
FUNCTION(, CONSTBUFFER_HANDLE, CONSTBUFFER_CreateFromBuffer, BUFFER_HANDLE, buffer),
FUNCTION(, CONSTBUFFER_HANDLE, CONSTBUFFER_CreateWithMoveMemory, unsigned char*, source, size_t, size),
FUNCTION(, CONSTBUFFER_HANDLE, CONSTBUFFER_CreateWithCustomFree, const unsigned char*, source, size_t, size, CONSTBUFFER_CUSTOM_FREE_FUNC, customFreeFunc, void*, customFreeFuncContext),
FUNCTION(, CONSTBUFFER_HANDLE, CONSTBUFFER_CreateFromOffsetAndSize, CONSTBUFFER_HANDLE, handle, size_t, offset, size_t, size),
FUNCTION(, CONSTBUFFER_HANDLE, CONSTBUFFER_CreateFromOffsetAndSizeWithCopy, CONSTBUFFER_HANDLE, handle, size_t, offset, size_t, size),
FUNCTION(, void, CONSTBUFFER_IncRef, CONSTBUFFER_HANDLE, constbufferHandle),
FUNCTION(, void, CONSTBUFFER_DecRef, CONSTBUFFER_HANDLE, constbufferHandle),
FUNCTION(, const CONSTBUFFER*, CONSTBUFFER_GetContent, CONSTBUFFER_HANDLE, constbufferHandle),
FUNCTION(, bool, CONSTBUFFER_HANDLE_contain_same, CONSTBUFFER_HANDLE, left, CONSTBUFFER_HANDLE, right)
)
```
### CONSTBUFFER_Create
```c
MOCKABLE_FUNCTION(, CONSTBUFFER_HANDLE, CONSTBUFFER_Create, const unsigned char*, source, size_t, size);
```
**SRS_CONSTBUFFER_02_001: [** If `source` is NULL and `size` is different than 0 then CONSTBUFFER_Create shall fail and return NULL. **]**
**SRS_CONSTBUFFER_02_002: [** Otherwise, `CONSTBUFFER_Create` shall create a copy of the memory area pointed to by `source` having `size` bytes. **]**
**SRS_CONSTBUFFER_02_003: [** If creating the copy fails then `CONSTBUFFER_Create` shall return NULL. **]**
**SRS_CONSTBUFFER_02_004: [** Otherwise `CONSTBUFFER_Create` shall return a non-NULL handle. **]**
**SRS_CONSTBUFFER_02_005: [** The non-NULL handle returned by `CONSTBUFFER_Create` shall have its ref count set to "1". **]**
### CONSTBUFFER_CreateFromBuffer
```c
MOCKABLE_FUNCTION(, CONSTBUFFER_HANDLE, CONSTBUFFER_CreateFromBuffer, BUFFER_HANDLE, buffer);
```
**SRS_CONSTBUFFER_02_006: [** If `buffer` is NULL then `CONSTBUFFER_CreateFromBuffer` shall fail and return NULL. **]**
**SRS_CONSTBUFFER_02_007: [** Otherwise, `CONSTBUFFER_CreateFromBuffer` shall copy the content of `buffer`. **]**
**SRS_CONSTBUFFER_02_008: [** If copying the content fails, then `CONSTBUFFER_CreateFromBuffer` shall fail and return NULL. **]**
**SRS_CONSTBUFFER_02_009: [** Otherwise, `CONSTBUFFER_CreateFromBuffer` shall return a non-NULL handle. **]**
**SRS_CONSTBUFFER_02_010: [** The non-NULL handle returned by `CONSTBUFFER_CreateFromBuffer` shall have its ref count set to "1". **]**
### CONSTBUFFER_CreateWithMoveMemory
```c
MOCKABLE_FUNCTION(, CONSTBUFFER_HANDLE, CONSTBUFFER_CreateWithMoveMemory, unsigned char*, source, size_t, size);
```
`CONSTBUFFER_CreateWithMoveMemory` creates a CONST buffer with move semantics for the memory given as argument (if succesfull, the const buffer owns the memory from that point on).
The memory is assumed to be freeable by a call to `free`.
**SRS_CONSTBUFFER_01_001: [** If `source` is NULL and `size` is different than 0 then `CONSTBUFFER_CreateWithMoveMemory` shall fail and return NULL. **]**
**SRS_CONSTBUFFER_01_004: [** If `source` is non-NULL and `size` is 0, the `source` pointer shall be owned (and freed) by the newly created instance of const buffer. **]**
**SRS_CONSTBUFFER_01_002: [** `CONSTBUFFER_CreateWithMoveMemory` shall store the `source` and `size` and return a non-NULL handle to the newly created const buffer. **]**
**SRS_CONSTBUFFER_01_003: [** The non-NULL handle returned by `CONSTBUFFER_CreateWithMoveMemory` shall have its ref count set to "1". **]**
**SRS_CONSTBUFFER_01_005: [** If any error occurs, `CONSTBUFFER_CreateWithMoveMemory` shall fail and return NULL. **]**
### CONSTBUFFER_CreateWithCustomFree
```c
MOCKABLE_FUNCTION(, CONSTBUFFER_HANDLE, CONSTBUFFER_CreateWithCustomFree, const unsigned char*, source, size_t, size, CONSTBUFFER_CUSTOM_FREE_FUNC, customFreeFunc, void*, customFreeFuncContext);
```
`CONSTBUFFER_CreateWithCustomFree` creates a CONST buffer with move semantics for the memory given as argument (if succesfull, the const buffer owns the memory from that point on).
The memory has to be free by calling the custom free function passed as argument.
**SRS_CONSTBUFFER_01_006: [** If `source` is NULL and `size` is different than 0 then `CONSTBUFFER_CreateWithCustomFree` shall fail and return NULL. **]**
**SRS_CONSTBUFFER_01_013: [** If `customFreeFunc` is NULL, `CONSTBUFFER_CreateWithCustomFree` shall fail and return NULL. **]**
**SRS_CONSTBUFFER_01_014: [** `customFreeFuncContext` shall be allowed to be NULL. **]**
**SRS_CONSTBUFFER_01_007: [** If `source` is non-NULL and `size` is 0, the `source` pointer shall be owned (and freed) by the newly created instance of const buffer. **]**
**SRS_CONSTBUFFER_01_008: [** `CONSTBUFFER_CreateWithCustomFree` shall store the `source` and `size` and return a non-NULL handle to the newly created const buffer. **]**
**SRS_CONSTBUFFER_01_009: [** `CONSTBUFFER_CreateWithCustomFree` shall store `customFreeFunc` and `customFreeFuncContext` in order to use them to free the memory when the CONST buffer resources are freed. **]**
**SRS_CONSTBUFFER_01_010: [** The non-NULL handle returned by `CONSTBUFFER_CreateWithCustomFree` shall have its ref count set to 1. **]**
**SRS_CONSTBUFFER_01_011: [** If any error occurs, `CONSTBUFFER_CreateWithMoveMemory` shall fail and return NULL. **]**
### CONSTBUFFER_CreateFromOffsetAndSize
```c
MOCKABLE_FUNCTION(, CONSTBUFFER_HANDLE, CONSTBUFFER_CreateFromOffsetAndSize, CONSTBUFFER_HANDLE, handle, size_t, offset, size_t, size)
```
Given an existing `handle` `CONSTBUFFER_CreateFromOffsetAndSize` creates another `CONSTBUFFER_HANDLE` from `size` bytes `handle` starting at `offset`.
**SRS_CONSTBUFFER_02_025: [** If `handle` is `NULL` then `CONSTBUFFER_CreateFromOffsetAndSize` shall fail and return `NULL`. **]**
**SRS_CONSTBUFFER_02_033: [** If `offset` is greater than `handles`'s size then `CONSTBUFFER_CreateFromOffsetAndSize` shall fail and return `NULL`. **]**
**SRS_CONSTBUFFER_02_027: [** If `offset` + `size` exceed `handles`'s size then `CONSTBUFFER_CreateFromOffsetAndSize` shall fail and return `NULL`. **]**
**SRS_CONSTBUFFER_02_028: [** `CONSTBUFFER_CreateFromOffsetAndSize` shall allocate memory for a new `CONSTBUFFER_HANDLE`'s content. **]**
**SRS_CONSTBUFFER_02_029: [** `CONSTBUFFER_CreateFromOffsetAndSize` shall set the ref count of the newly created `CONSTBUFFER_HANDLE` to the initial value. **]**
**SRS_CONSTBUFFER_02_030: [** `CONSTBUFFER_CreateFromOffsetAndSize` shall increment the reference count of `handle`. **]**
**SRS_CONSTBUFFER_02_031: [** `CONSTBUFFER_CreateFromOffsetAndSize` shall succeed and return a non-`NULL` value. **]**
**SRS_CONSTBUFFER_02_032: [** If there are any failures then `CONSTBUFFER_CreateFromOffsetAndSize` shall fail and return `NULL`. **]**
### CONSTBUFFER_CreateFromOffsetAndSizeWithCopy
```c
FUNCTION(, CONSTBUFFER_HANDLE, CONSTBUFFER_CreateFromOffsetAndSizeWithCopy, CONSTBUFFER_HANDLE, handle, size_t, offset, size_t, size)
```
`CONSTBUFFER_CreateFromOffsetAndSizeWithCopy` creates a new CONSTBUFFER starting with the memory at `offset` in `handle` and having `size` bytes by copying (`memcpy`) those bytes. This creates a new `CONSTBUFFER_HANDLE` with its ref count set to 1.
**SRS_CONSTBUFFER_02_034: [** If `handle` is `NULL` then `CONSTBUFFER_CreateFromOffsetAndSizeWithCopy` shall fail and return `NULL`. **]**
**SRS_CONSTBUFFER_02_035: [** If `offset` exceeds the capacity of `handle` then `CONSTBUFFER_CreateFromOffsetAndSizeWithCopy` shall fail and return `NULL`. **]**
**SRS_CONSTBUFFER_02_036: [** If `offset` + `size` exceed the capacity of `handle` then `CONSTBUFFER_CreateFromOffsetAndSizeWithCopy` shall fail and return `NULL`. **]**
**SRS_CONSTBUFFER_02_037: [** `CONSTBUFFER_CreateFromOffsetAndSizeWithCopy` shall allocate enough memory to hold `CONSTBUFFER_HANDLE` and `size` bytes. **]**
**SRS_CONSTBUFFER_02_038: [** If `size` is 0 then `CONSTBUFFER_CreateFromOffsetAndSizeWithCopy` shall set the pointed to buffer to `NULL`. **]**
**SRS_CONSTBUFFER_02_039: [** `CONSTBUFFER_CreateFromOffsetAndSizeWithCopy` shall set the pointed to a non-`NULL` value that contains the same bytes as `offset`...`offset`+`size`-1 of `handle`. **]**
**SRS_CONSTBUFFER_02_040: [** If there are any failures then `CONSTBUFFER_CreateFromOffsetAndSizeWithCopy` shall fail and return `NULL`. **]**
### CONSTBUFFER_IncRef
```c
MOCKABLE_FUNCTION(, void, CONSTBUFFER_IncRef, CONSTBUFFER_HANDLE, constbufferHandle);
```
**SRS_CONSTBUFFER_02_013: [** If `constbufferHandle` is NULL then `CONSTBUFFER_IncRef` shall return. **]**
**SRS_CONSTBUFFER_02_014: [** Otherwise, `CONSTBUFFER_IncRef` shall increment the reference count. **]**
### CONSTBUFFER_DecRef
```c
MOCKABLE_FUNCTION(, void, CONSTBUFFER_DecRef, CONSTBUFFER_HANDLE, constbufferHandle);
```
**SRS_CONSTBUFFER_02_015: [** If `constbufferHandle` is NULL then `CONSTBUFFER_DecRef` shall do nothing. **]**
**SRS_CONSTBUFFER_02_016: [** Otherwise, `CONSTBUFFER_DecRef` shall decrement the refcount on the `constbufferHandle` handle. **]**
**SRS_CONSTBUFFER_02_017: [** If the refcount reaches zero, then `CONSTBUFFER_DecRef` shall deallocate all resources used by the CONSTBUFFER_HANDLE. **]**
**SRS_CONSTBUFFER_01_012: [** If the buffer was created by calling `CONSTBUFFER_CreateWithCustomFree`, the `customFreeFunc` function shall be called to free the memory, while passed `customFreeFuncContext` as argument. **]**
**SRS_CONSTBUFFER_02_024: [** If the `constbufferHandle` was created by calling `CONSTBUFFER_CreateFromOffsetAndSize` then `CONSTBUFFER_DecRef` shall decrement the ref count of the original `handle` passed to `CONSTBUFFER_CreateFromOffsetAndSize`. **]**
### CONSTBUFFER_GetContent
```c
MOCKABLE_FUNCTION(, const CONSTBUFFER*, CONSTBUFFER_GetContent, CONSTBUFFER_HANDLE, constbufferHandle);
```
**SRS_CONSTBUFFER_02_011: [** If `constbufferHandle` is NULL then CONSTBUFFER_GetContent shall return NULL. **]**
**SRS_CONSTBUFFER_02_012: [** Otherwise, `CONSTBUFFER_GetContent` shall return a `const CONSTBUFFER*` that matches byte by byte the original bytes used to created the const buffer and has the same length. **]**
### CONSTBUFFER_HANDLE_contain_same
```c
MOCKABLE_FUNCTION(, bool, CONSTBUFFER_HANDLE_contain_same, CONSTBUFFER_HANDLE, left, CONSTBUFFER_HANDLE, right);
```
`CONSTBUFFER_HANDLE_contain_same` returns `true` if `left` and `right` have the same content.
**SRS_CONSTBUFFER_02_018: [** If `left` is `NULL` and `right` is `NULL` then `CONSTBUFFER_HANDLE_contain_same` shall return `true`. **]**
**SRS_CONSTBUFFER_02_019: [** If `left` is `NULL` and `right` is not `NULL` then `CONSTBUFFER_HANDLE_contain_same` shall return `false`. **]**
**SRS_CONSTBUFFER_02_020: [** If `left` is not `NULL` and `right` is `NULL` then `CONSTBUFFER_HANDLE_contain_same` shall return `false`. **]**
**SRS_CONSTBUFFER_02_021: [** If `left`'s size is different than `right`'s size then `CONSTBUFFER_HANDLE_contain_same` shall return `false`. **]**
**SRS_CONSTBUFFER_02_022: [** If `left`'s buffer is contains different bytes than `rights`'s buffer then `CONSTBUFFER_HANDLE_contain_same` shall return `false`. **]**
**SRS_CONSTBUFFER_02_023: [** `CONSTBUFFER_HANDLE_contain_same` shall return `true`. **]**

Просмотреть файл

@ -9,7 +9,7 @@ The `file` module provides a platform-independent API for asynchronous file oper
-`file_destroy`: closes the given file handle.
-`file_write_async`: enqueues an asynchronous write request for a file at a given position.
-`file_read_async`: enqueues an asynchronous read request for a file at a given position and size.
-`file_extend_filesize`: expands the given file to be of desired size.
-`file_extend`: expands the given file to be of desired size.
## Exposed API
@ -33,11 +33,14 @@ typedef void(*FILE_REPORT_FAULT)(void* user_report_fault_context, const char* in
typedef void(*FILE_WRITE_CB)(void* user_context, bool is_successful);
typedef void(*FILE_READ_CB)(void* user_context, bool is_successful, CONSTBUFFER_HANDLE content);
MOCKABLE_FUNCTION(, FILE_HANDLE, file_create,FILE_REPORT_FAULT, user_report_fault_callback, void*, user_report_fault_context, EXECUTION_ENGINE_HANDLE, execution_engine, const char*, full_file_name);
MOCKABLE_FUNCTION(, FILE_HANDLE, file_create, EXECUTION_ENGINE_HANDLE, execution_engine, const char*, full_file_name, FILE_REPORT_FAULT, user_report_fault_callback, void*, user_report_fault_context);
MOCKABLE_FUNCTION(, void, file_destroy, FILE_HANDLE, handle);
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_WRITE_ASYNC_RESULT, file_write_async, FILE_HANDLE, handle, CONSTBUFFER_HANDLE, source, uint64_t, position, FILE_WRITE_CB, user_callback, void*, user_context)(0, MU_FAILURE);
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_READ_ASYNC_RESULT, file_read_async, FILE_HANDLE, handle, uint32_t, size, uint64_t, position, FILE_READ_CB, user_callback, void*, user_context)(0, MU_FAILURE);
MOCKABLE_FUNCTION_WITH_RETURNS(, int, file_extend_filesize, FILE_HANDLE, handle, uint64_t, desired_size, bool, has_manage_volume)(0, MU_FAILURE);
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_WRITE_ASYNC_RESULT, file_write_async, FILE_HANDLE, handle, CONSTBUFFER_HANDLE, source, uint64_t, position, FILE_WRITE_CB, user_callback, void*, user_context)(FILE_WRITE_ASYNC_OK, FILE_WRITE_ASYNC_ERROR);
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_READ_ASYNC_RESULT, file_read_async, FILE_HANDLE, handle, uint32_t, size, uint64_t, position, FILE_READ_CB, user_callback, void*, user_context)(FILE_READ_ASYNC_OK, FILE_READ_ASYNC_ERROR);
MOCKABLE_FUNCTION_WITH_RETURNS(, int, file_extend, FILE_HANDLE, handle, uint64_t, desired_size)(0, MU_FAILURE);
```
## file_create
@ -46,7 +49,7 @@ MOCKABLE_FUNCTION_WITH_RETURNS(, int, file_extend_filesize, FILE_HANDLE, handle,
MOCKABLE_FUNCTION(, FILE_HANDLE, file_create,FILE_REPORT_FAULT, user_report_fault_callback, void*, user_report_fault_context, EXECUTION_ENGINE_HANDLE, execution_engine, const char*, full_file_name);
```
`file_create` creates a file by the name of `full_file_name` it doesn't exist. `file_create` opens a file by the name `full_file_name` and returns its file handle.
If a file by the name `full_file_name` does not exist, `file_create` creates a file by that name, opens it and returns its handle. If the file does exist, `file_create` opens the file and returns its handle.
**SRS_FILE_43_033: [** If `execution_engine` is `NULL`, `file_create` shall fail and return `NULL`. **]**
@ -58,6 +61,8 @@ MOCKABLE_FUNCTION(, FILE_HANDLE, file_create,FILE_REPORT_FAULT, user_report_faul
**SRS_FILE_43_001: [** `file_create` shall open the file named `full_file_name` for asynchronous operations and return its handle. **]**
**SRS_FILE_43_038: [** `file_create` shall register `user_report_fault_callback` with argument `user_report_fault_context` as the callback function to be called when the callback specified by the user for a specific asynchronous operation cannot be called. **]**
**SRS_FILE_43_034: [** If there are any failures, `file_create` shall fail and return `NULL`. **]**
## file_destroy
@ -77,15 +82,17 @@ MOCKABLE_FUNCTION(, void, file_destroy, FILE_HANDLE, handle);
## file_write_async
```c
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_WRITE_ASYNC_RESULT, file_write_async, FILE_HANDLE, handle, CONSTBUFFER_HANDLE, source, uint64_t, position, FILE_WRITE_CB, user_callback, void*, user_context)(0, MU_FAILURE);
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_WRITE_ASYNC_RESULT, file_write_async, FILE_HANDLE, handle, CONSTBUFFER_HANDLE, source, uint64_t, position, FILE_WRITE_CB, user_callback, void*, user_context)(FILE_WRITE_ASYNC_OK, FILE_WRITE_ASYNC_ERROR);
```
`file_write_async` issues an asynchronous write request.
`file_write_async` issues an asynchronous write request. If the write goes beyond the size of the file, the file grows to accomodate the write. On linux, the grow-and-write is atomic. On Windows, ...(waiting for response from Windows 32-bit Sys Prgrmmg Questions).
**SRS_FILE_43_009: [** If `handle` is `NULL` then `file_write_async` shall fail and return `FILE_WRITE_ASYNC_INVALID_ARGS`. **]**
**SRS_FILE_43_010: [** If `source` is `NULL` then `file_write_async` shall fail and return `FILE_WRITE_ASYNC_INVALID_ARGS`. **]**
**SRS_FILE_43_040: [** If `position` is greater than `INT64_MAX`, then `file_write_async` shall fail and return `FILE_WRITE_ASYNC_INVALID_ARGS`. **]**
**SRS_FILE_43_012: [** If `user_callback` is `NULL` then `file_write_async` shall fail and return `FILE_WRITE_ASYNC_INVALID_ARGS`. **]**
**SRS_FILE_43_014: [** `file_write_async` shall enqueue a write request to write `source`'s content to the `position` offset in the file. **]**
@ -101,7 +108,7 @@ MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_WRITE_ASYNC_RESULT, file_write_async, FILE
## file_read_async
```c
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_READ_ASYNC_RESULT, file_read_async, FILE_HANDLE, handle, uint32_t, size, uint64_t, position, FILE_READ_CB, user_callback, void*, user_context)(0, MU_FAILURE);
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_READ_ASYNC_RESULT, file_read_async, FILE_HANDLE, handle, uint32_t, size, uint64_t, position, FILE_READ_CB, user_callback, void*, user_context)(FILE_READ_ASYNC_OK, FILE_READ_ASYNC_ERROR);
```
`file_read_async` issues an asynchronous read request.
@ -116,28 +123,30 @@ MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_READ_ASYNC_RESULT, file_read_async, FILE_H
**SRS_FILE_43_036: [** If the call to read the file fails, `file_read_async` shall fail and return `FILE_READ_ASYNC_READ_ERROR`. **]**
**SRS_FILE_43_016: [** `file_read_async` shall call `user_call_back` passing `user_context` and `success` depending on the success of the asynchronous write operation.**]**
**SRS_FILE_43_039: [** If `position` + `size` exceeds the size of the file, `user_callback` shall be called with `success` as `false`. **]**
**SRS_FILE_43_016: [** `file_read_async` shall call `user_callback` passing `user_context` and `success` depending on the success of the asynchronous write operation.**]**
**SRS_FILE_43_022: [** If there are any failures then `file_read_async` shall fail and return `FILE_READ_ASYNC_ERROR`. **]**
**SRS_FILE_43_031: [** `file_read_async` shall succeed and return `FILE_READ_ASYNC_OK`. **]**
## file_extend_filesize
## file_extend
```c
MOCKABLE_FUNCTION_WITH_RETURNS(, int, file_extend_filesize, FILE_HANDLE, handle, uint64_t, desired_size, bool, has_manage_volume)(0, MU_FAILURE);
MOCKABLE_FUNCTION_WITH_RETURNS(, int, file_extend, FILE_HANDLE, handle, uint64_t, desired_size)(0, MU_FAILURE);
```
`file_extend_filesize` resizes the file to `desired_size`.
`file_extend` grows the file to `desired_size`.
**SRS_FILE_43_024: [** If `handle` is `NULL`, `file_extend_filesize` shall return a non-zero value. **]**
**SRS_FILE_43_024: [** If `handle` is `NULL`, `file_extend` shall return a non-zero value. **]**
**SRS_FILE_43_025: [** If `desired_size` is greater than `INT64_MAX`, `file_extend_filesize` shall return a non-zero value. **]**
**SRS_FILE_43_025: [** If `desired_size` is greater than `INT64_MAX`, `file_extend` shall return a non-zero value. **]**
**SRS_FILE_43_026: [** If `desired_size` is less than the current size of the file, `file_extend_filesize` shall return a non-zero value. **]**
**SRS_FILE_43_026: [** If `desired_size` is less than the current size of the file, `file_extend` shall return a non-zero value. **]**
**SRS_FILE_43_027: [** If `has_manage_volume` is `true`, `file_extend_filesize` shall set the valid file data size of the given file to `desired_size`. **]**
**SRS_FILE_43_027: [** `file_extend` shall set the valid file data size of the given file to `desired_size`. **]**
**SRS_FILE_43_028: [** If there are any failures, `file_extend_filesize` shall return a non-zero value. **]**
**SRS_FILE_43_028: [** If there are any failures, `file_extend` shall return a non-zero value. **]**
**SRS_FILE_43_029: [** If there are no failures, `file_extend_filesize` will return `0`. **]**
**SRS_FILE_43_029: [** If there are no failures, `file_extend` will return `0`. **]**

Просмотреть файл

@ -1,46 +0,0 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#ifndef BUFFER__H
#define BUFFER__H
#ifdef __cplusplus
#include <cstddef>
#else
#include <stddef.h>
#include <stdbool.h>
#endif
#include "umock_c/umock_c_prod.h"
#ifdef __cplusplus
extern "C"
{
#endif
typedef struct BUFFER_TAG* BUFFER_HANDLE;
MOCKABLE_FUNCTION(, BUFFER_HANDLE, BUFFER_new);
MOCKABLE_FUNCTION(, BUFFER_HANDLE, BUFFER_create, const unsigned char*, source, size_t, size);
MOCKABLE_FUNCTION(, BUFFER_HANDLE, BUFFER_create_with_size, size_t, buff_size);
MOCKABLE_FUNCTION(, void, BUFFER_delete, BUFFER_HANDLE, handle);
MOCKABLE_FUNCTION(, int, BUFFER_pre_build, BUFFER_HANDLE, handle, size_t, size);
MOCKABLE_FUNCTION(, int, BUFFER_build, BUFFER_HANDLE, handle, const unsigned char*, source, size_t, size);
MOCKABLE_FUNCTION(, int, BUFFER_append_build, BUFFER_HANDLE, handle, const unsigned char*, source, size_t, size);
MOCKABLE_FUNCTION(, int, BUFFER_unbuild, BUFFER_HANDLE, handle);
MOCKABLE_FUNCTION(, int, BUFFER_enlarge, BUFFER_HANDLE, handle, size_t, enlargeSize);
MOCKABLE_FUNCTION(, int, BUFFER_shrink, BUFFER_HANDLE, handle, size_t, decreaseSize, bool, fromEnd);
MOCKABLE_FUNCTION(, int, BUFFER_content, BUFFER_HANDLE, handle, const unsigned char**, content);
MOCKABLE_FUNCTION(, int, BUFFER_size, BUFFER_HANDLE, handle, size_t*, size);
MOCKABLE_FUNCTION(, int, BUFFER_append, BUFFER_HANDLE, handle1, BUFFER_HANDLE, handle2);
MOCKABLE_FUNCTION(, int, BUFFER_prepend, BUFFER_HANDLE, handle1, BUFFER_HANDLE, handle2);
MOCKABLE_FUNCTION(, int, BUFFER_fill, BUFFER_HANDLE, handle, unsigned char, fill_char);
MOCKABLE_FUNCTION(, unsigned char*, BUFFER_u_char, BUFFER_HANDLE, handle);
MOCKABLE_FUNCTION(, size_t, BUFFER_length, BUFFER_HANDLE, handle);
MOCKABLE_FUNCTION(, BUFFER_HANDLE, BUFFER_clone, BUFFER_HANDLE, handle);
#ifdef __cplusplus
}
#endif
#endif /* BUFFER__H */

Просмотреть файл

@ -1,63 +0,0 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#ifndef CONSTBUFFER_H
#define CONSTBUFFER_H
#ifdef __cplusplus
#include <cstddef>
#else
#include <stddef.h>
#include <stdbool.h>
#endif
#include "buffer_.h"
#include "umock_c/umock_c_prod.h"
#ifdef __cplusplus
extern "C"
{
#endif
/*this is the handle*/
typedef struct CONSTBUFFER_HANDLE_DATA_TAG* CONSTBUFFER_HANDLE;
/*this is what is returned when the content of the buffer needs access*/
typedef struct CONSTBUFFER_TAG
{
const unsigned char* buffer;
size_t size;
} CONSTBUFFER;
typedef void(*CONSTBUFFER_CUSTOM_FREE_FUNC)(void* context);
MOCKABLE_INTERFACE(constbuffer,
/*this creates a new constbuffer from a memory area*/
FUNCTION(, CONSTBUFFER_HANDLE, CONSTBUFFER_Create, const unsigned char*, source, size_t, size),
/*this creates a new constbuffer from an existing BUFFER_HANDLE*/
FUNCTION(, CONSTBUFFER_HANDLE, CONSTBUFFER_CreateFromBuffer, BUFFER_HANDLE, buffer),
FUNCTION(, CONSTBUFFER_HANDLE, CONSTBUFFER_CreateWithMoveMemory, unsigned char*, source, size_t, size),
FUNCTION(, CONSTBUFFER_HANDLE, CONSTBUFFER_CreateWithCustomFree, const unsigned char*, source, size_t, size, CONSTBUFFER_CUSTOM_FREE_FUNC, customFreeFunc, void*, customFreeFuncContext),
FUNCTION(, CONSTBUFFER_HANDLE, CONSTBUFFER_CreateFromOffsetAndSize, CONSTBUFFER_HANDLE, handle, size_t, offset, size_t, size),
FUNCTION(, CONSTBUFFER_HANDLE, CONSTBUFFER_CreateFromOffsetAndSizeWithCopy, CONSTBUFFER_HANDLE, handle, size_t, offset, size_t, size),
FUNCTION(, void, CONSTBUFFER_IncRef, CONSTBUFFER_HANDLE, constbufferHandle),
FUNCTION(, void, CONSTBUFFER_DecRef, CONSTBUFFER_HANDLE, constbufferHandle),
FUNCTION(, const CONSTBUFFER*, CONSTBUFFER_GetContent, CONSTBUFFER_HANDLE, constbufferHandle),
FUNCTION(, bool, CONSTBUFFER_HANDLE_contain_same, CONSTBUFFER_HANDLE, left, CONSTBUFFER_HANDLE, right)
)
#ifdef __cplusplus
}
#endif
#endif /* CONSTBUFFER_H */

Просмотреть файл

@ -11,10 +11,10 @@
#include <stdint.h>
#endif
#include "umock_c/umock_c_prod.h"
#include "azure_macro_utils/macro_utils.h"
#include "constbuffer.h"
#include "execution_engine.h"
#include "umock_c/umock_c_prod.h"
#ifdef __cplusplus
extern "C" {
#endif
@ -39,15 +39,14 @@ typedef void(*FILE_REPORT_FAULT)(void* user_report_fault_context, const char* in
typedef void(*FILE_WRITE_CB)(void* user_context, bool is_successful);
typedef void(*FILE_READ_CB)(void* user_context, bool is_successful, CONSTBUFFER_HANDLE content);
MOCKABLE_FUNCTION(, FILE_HANDLE, file_create, EXECUTION_ENGINE_HANDLE, execution_engine, const char*, full_file_name, FILE_REPORT_FAULT, user_report_fault_callback, void*, user_report_fault_context);
MOCKABLE_FUNCTION(, void, file_destroy, FILE_HANDLE, handle);
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_WRITE_ASYNC_RESULT, file_write_async, FILE_HANDLE, handle, CONSTBUFFER_HANDLE, source, uint64_t, position, FILE_WRITE_CB, user_callback, void*, user_context)(FILE_WRITE_ASYNC_OK, FILE_WRITE_ASYNC_ERROR);
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_READ_ASYNC_RESULT, file_read_async, FILE_HANDLE, handle, uint32_t, size, uint64_t, position, FILE_READ_CB, user_callback, void*, user_context)(FILE_READ_ASYNC_OK, FILE_READ_ASYNC_ERROR);
MOCKABLE_FUNCTION_WITH_RETURNS(, int, file_extend_filesize, FILE_HANDLE, handle, uint64_t, desired_size, bool, has_manage_volume)(0, MU_FAILURE);
MOCKABLE_FUNCTION_WITH_RETURNS(, int, file_extend, FILE_HANDLE, handle, uint64_t, desired_size)(0, MU_FAILURE);
#ifdef __cplusplus
}
#endif
#endif
#endif

Просмотреть файл

@ -24,4 +24,4 @@ endif()
add_library(reals_pal_interface INTERFACE)
target_include_directories(reals_pal_interface INTERFACE ${CMAKE_CURRENT_LIST_DIR})
target_link_libraries(reals_pal_interface INTERFACE azure_c_logging pal_common)
target_link_libraries(reals_pal_interface INTERFACE azure_c_logging pal_interfaces)

Просмотреть файл

@ -10,7 +10,6 @@
#include <stdint.h>
#endif
#include "umock_c/umock_c_prod.h"
#include "azure_macro_utils/macro_utils.h"
#include "constbuffer.h"
#include "file.h"
@ -19,26 +18,20 @@
extern "C" {
#endif
typedef struct FILE_WRITE_DATA_TAG
typedef struct FILE_WRITE_DATA_CONTEXT_TAG
{
FILE_WRITE_CB user_callback;
void* user_context;
CONSTBUFFER_HANDLE source;
}FILE_WRITE_DATA;
}FILE_WRITE_DATA_CONTEXT;
typedef struct FILE_READ_DATA_TAG
typedef struct FILE_READ_DATA_CONTEXT_TAG
{
FILE_READ_CB user_callback;
void* user_context;
uint32_t size;
unsigned char* destination;
}FILE_READ_DATA;
typedef union FILE_IO_DATA_TAG
{
FILE_READ_DATA read_data;
FILE_WRITE_DATA write_data;
}FILE_IO_DATA;
CONSTBUFFER_HANDLE destination;
}FILE_READ_DATA_CONTEXT;
#define FILE_ASYNC_OPERATION_VALUES \
FILE_ASYNC_WRITE, \
@ -49,4 +42,4 @@ MU_DEFINE_ENUM(FILE_ASYNC_OPERATION, FILE_ASYNC_OPERATION_VALUES)
#ifdef __cplusplus
}
#endif
#endif
#endif

Просмотреть файл

@ -1,10 +1,12 @@
#Copyright (C) Microsoft Corporation. All rights reserved.
set(pal_linux_h_files
${pal_common_h_files}
inc/refcount_os.h
)
set(pal_linux_c_files
${pal_common_c_files}
src/interlocked_linux.c
src/lock_pthreads.c
src/platform_linux.c
@ -18,10 +20,11 @@ FILE(GLOB pal_linux_md_files "devdoc/*.md")
SOURCE_GROUP(devdoc FILES ${pal_linux_md_files})
include_directories(${CMAKE_CURRENT_LIST_DIR}/inc)
include_directories(../common/inc)
add_library(pal_linux ${pal_linux_h_files} ${pal_linux_c_files} ${pal_linux_md_files})
target_link_libraries(pal_linux pal_interfaces pal_common pal_internal pthread m rt uuid)
target_link_libraries(pal_linux pal_interfaces pal_internal pthread m rt uuid)
target_include_directories(pal_linux PUBLIC ${CMAKE_CURRENT_LIST_DIR}/inc)
add_subdirectory(tests)
add_subdirectory(../common/tests common/tests)

Просмотреть файл

@ -10,7 +10,7 @@ Linux implementation of the `file` module.
-`file_write_async` and `file_read_async` create [`sigevent`](https://man7.org/linux/man-pages/man7/sigevent.7.html)s to specify callbacks.
-`file_write_async` uses [`aio_write`](https://man7.org/linux/man-pages/man3/aio_write.3.html).
-`file_read_async` uses [`aio_read`](https://man7.org/linux/man-pages/man3/aio_read.3.html).
-`file_extend` uses [`ftruncate`](https://www.man7.org/linux/man-pages/man3/ftruncate.3p.html)
## Exposed API
```c
@ -36,9 +36,11 @@ typedef void(*FILE_READ_CB)(void* user_context, bool is_successful, CONSTBUFFER_
MOCKABLE_FUNCTION(, FILE_HANDLE, file_create, EXECUTION_ENGINE_HANDLE, execution_engine, const char*, full_file_name, FILE_REPORT_FAULT, user_report_fault_callback, void*, user_report_fault_context);
MOCKABLE_FUNCTION(, void, file_destroy, FILE_HANDLE, handle);
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_WRITE_ASYNC_RESULT, file_write_async, FILE_HANDLE, handle, CONSTBUFFER_HANDLE, source, uint64_t, position, FILE_WRITE_CB, user_callback, void*, user_context)(0, MU_FAILURE);
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_READ_ASYNC_RESULT, file_read_async, FILE_HANDLE, handle, uint32_t, size, uint64_t, position, FILE_READ_CB, user_callback, void*, user_context)(0, MU_FAILURE);
MOCKABLE_FUNCTION_WITH_RETURNS(, int, file_extend_filesize, FILE_HANDLE, handle, uint64_t, desired_size, bool, has_manage_volume)(0, MU_FAILURE);
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_WRITE_ASYNC_RESULT, file_write_async, FILE_HANDLE, handle, CONSTBUFFER_HANDLE, source, uint64_t, position, FILE_WRITE_CB, user_callback, void*, user_context)(FILE_WRITE_ASYNC_OK, FILE_WRITE_ASYNC_ERROR);
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_READ_ASYNC_RESULT, file_read_async, FILE_HANDLE, handle, uint32_t, size, uint64_t, position, FILE_READ_CB, user_callback, void*, user_context)(FILE_READ_ASYNC_OK, FILE_READ_ASYNC_ERROR);
MOCKABLE_FUNCTION_WITH_RETURNS(, int, file_extend, FILE_HANDLE, handle, uint64_t, desired_size, bool, has_manage_volume)(0, MU_FAILURE);
```
## file_create
@ -53,7 +55,7 @@ MOCKABLE_FUNCTION(, FILE_HANDLE, file_create, EXECUTION_ENGINE_HANDLE, execution
**SRS_FILE_LINUX_43_029: [** `file_create` shall allocate a `FILE_HANDLE`. **]**
**SRS_FILE_LINUX_43_001: [** `file_create` shall call `open` with `full_file_name` as `pathname` and flags `O_CREAT` and `O_RDWR`. **]**
**SRS_FILE_LINUX_43_001: [** `file_create` shall call `open` with `full_file_name` as `pathname` and flags `O_CREAT`, `O_RDWR`, `O_DIRECT` and `O_LARGEFILE`. **]**
**SRS_FILE_LINUX_43_002: [** `file_create` shall return the file handle returned by the call to `open`.**]**
@ -73,7 +75,7 @@ MOCKABLE_FUNCTION(, void, file_destroy, FILE_HANDLE, handle);
## file_write_async
```c
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_WRITE_ASYNC_RESULT, file_write_async, FILE_HANDLE, handle, CONSTBUFFER_HANDLE, source, uint64_t, position, FILE_WRITE_CB, user_callback, void*, user_context)(0, MU_FAILURE);
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_WRITE_ASYNC_RESULT, file_write_async, FILE_HANDLE, handle, CONSTBUFFER_HANDLE, source, uint64_t, position, FILE_WRITE_CB, user_callback, void*, user_context)(FILE_WRITE_ASYNC_OK, FILE_WRITE_ASYNC_ERROR);
```
**SRS_FILE_LINUX_43_031: [** If `handle` is `NULL` then `file_write_async` shall fail and return `FILE_WRITE_ASYNC_INVALID_ARGS`. **]**
@ -82,15 +84,13 @@ MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_WRITE_ASYNC_RESULT, file_write_async, FILE
**SRS_FILE_LINUX_43_033: [** If `user_callback` is `NULL` then `file_write_async` shall fail and return `FILE_WRITE_ASYNC_INVALID_ARGS`. **]**
**SRS_FILE_LINUX_43_019: [** `file_write_async` shall create a `FILE_LINUX_IO` struct with `handle` as `handle`, `FILE_ASYNC_WRITE` as `type`. **]**
**SRS_FILE_LINUX_43_019: [** `file_write_async` shall allocate a struct to hold `handle`, `source`, `user_callback` and `user_context`. **]**
**SRS_FILE_LINUX_43_020: [** `file_write_async` shall populate the `data` field of the `FILE_LINUX_IO` struct using `source`, `user_callback` and `user_context`. **]**
**SRS_FILE_LINUX_43_004: [** `file_write_async` shall allocate a `sigevent` struct with `SIGEV_THREAD` as `sigev_notify`, the allocated struct as `sigev_value`, `on_file_write_complete_linux` as `sigev_notify_function`, `NULL` as `sigev_notify_attributes`. **]**
**SRS_FILE_LINUX_43_004: [** `file_write_async` shall initialize a `sigevent` struct with `SIGEV_THREAD` as `sigev_notify`, the created `FILE_LINUX_IO` struct as `sigev_value`, `on_file_io_complete_linux` as `sigev_notify_function`, `NULL` as `sigev_notify_attributes`(unsure about what `sigev_notify_attributes` should be). **]**
**SRS_FILE_LINUX_43_005: [** `file_write_async` shall allocate an `aiocb` struct with `handle` as `aio_fildes`, `position` as `aio_offset`, source as `aio_buf`, `source->alias->size` as `aio_nbytes`, and the allocated `sigevent` struct as `aio_sigevent`. **]**
**SRS_FILE_LINUX_43_005: [** `file_write_async` shall initialize an `aiocb` struct with `handle` as `aio_fildes`, `position` as `aio_offset`, source as `aio_buf`, `source->alias->size` as `aio_nbytes`, and the initialized `sigevent` struct as `aio_sigevent`. **]**
**SRS_FILE_LINUX_43_006: [** `file_write_async` shall call `aio_write` with the initialized `aiocb` struct as `aiocbp`.**]**
**SRS_FILE_LINUX_43_006: [** `file_write_async` shall call `aio_write` with the allocated `aiocb` struct as `aiocbp`.**]**
**SRS_FILE_LINUX_43_012: [** If `aio_write` fails, `file_write_async` shall return `FILE_WRITE_ASYNC_WRITE_ERROR`. **]**
@ -101,22 +101,24 @@ MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_WRITE_ASYNC_RESULT, file_write_async, FILE
## file_read_async
```c
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_READ_ASYNC_RESULT, file_read_async, FILE_HANDLE, handle, uint32_t, size, uint64_t, position, FILE_READ_CB, user_callback, void*, user_context)(0, MU_FAILURE);
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_READ_ASYNC_RESULT, file_read_async, FILE_HANDLE, handle, uint32_t, size, uint64_t, position, FILE_READ_CB, user_callback, void*, user_context)(FILE_READ_ASYNC_OK, FILE_READ_ASYNC_ERROR);
```
**SRS_FILE_LINUX_43_034: [** If `handle` is `NULL` then `file_read_async` shall fail and return `FILE_READ_ASYNC_INVALID_ARGS`. **]**
**SRS_FILE_LINUX_43_035: [** If `user_callback` is `NULL` then `file_read_async` shall fail and return `FILE_READ_ASYNC_INVALID_ARGS`. **]**
**SRS_FILE_LINUX_43_016: [** `file_read_async` shall create a `FILE_LINUX_IO` struct with `handle` as `handle`, `FILE_ASYNC_READ` as `type`. **]**
**SRS_FILE_LINUX_43_043: [** `file_read_async` shall allocate a buffer of size `size`. **]**
**SRS_FILE_LINUX_43_017: [** `file_read_async` shall populate the `data` field of the `FILE_LINUX_IO` struct using `user_callback` and `user_context`. **]**
**SRS_FILE_LINUX_43_044: [** `file_read_async` shall create a `CONSTBUFFER_HANDLE` using the allocated buffer. **]**
**SRS_FILE_LINUX_43_008: [** `file_read_async` shall initialize a `sigevent` struct with `SIGEV_THREAD` as `sigev_notify`, `user_context` as `sigev_value`, `user_callback` as `sigev_notify_function`, `NULL` as `sigev_notify_attributes`(unsure about what `sigev_notify_attributes` should be). **]**
**SRS_FILE_LINUX_43_045: [** `file_read_async` shall allocate a struct to hold `handle`, the created `CONSTBUFFER_HANDLE`, `user_callback` and `user_context`. **]**
**SRS_FILE_LINUX_43_009: [** `file_read_async` shall initialize an `aiocb` struct with `handle` as `aio_fildes`, `position` as `aio_offset`, source as `aio_buf`, `source->alias->size` as `aio_nbytes`, and the initialized `sigevent` struct as `aio_sigevent`. **]**
**SRS_FILE_LINUX_43_008: [** `file_read_async` shall allocate a `sigevent` struct with `SIGEV_THREAD` as `sigev_notify`, `user_context` as `sigev_value`, `on_file_read_complete_linux` as `sigev_notify_function`, `NULL` as `sigev_notify_attributes`. **]**
**SRS_FILE_LINUX_43_010: [** `file_read_async` shall call `aio_read` with the initialized `aiocb` struct as `aiocbp`. **]**
**SRS_FILE_LINUX_43_009: [** `file_read_async` shall allocate an `aiocb` struct with `handle` as `aio_fildes`, `position` as `aio_offset`, the allocated buffer as `aio_buf`, `size` as `aio_nbytes`, and the allocated `sigevent` struct as `aio_sigevent`. **]**
**SRS_FILE_LINUX_43_010: [** `file_read_async` shall call `aio_read` with the allocated `aiocb` struct as `aiocbp`. **]**
**SRS_FILE_LINUX_43_011: [** If `aio_read` fails, `file_read_async` shall return `FILE_READ_ASYNC_READ_ERROR`. **]**
@ -125,35 +127,41 @@ MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_READ_ASYNC_RESULT, file_read_async, FILE_H
**SRS_FILE_LINUX_43_015: [** If there are any failures, `file_read_async` shall return `FILE_READ_ASYNC_ERROR`. **]**
## file_extend_filesize
## file_extend
```c
MOCKABLE_FUNCTION_WITH_RETURNS(, int, file_extend_filesize, FILE_HANDLE, handle, uint64_t, desired_size, bool, has_manage_volume)(0, MU_FAILURE);
MOCKABLE_FUNCTION_WITH_RETURNS(, int, file_extend, FILE_HANDLE, handle, uint64_t, desired_size, bool, has_manage_volume)(0, MU_FAILURE);
```
**SRS_FILE_LINUX_43_018: [** `file_extend_filesize` shall return 0. **]**
**SRS_FILE_LINUX_43_018: [** `file_extend` shall return 0. **]**
Will be implemented later.
## on_file_io_complete_linux
## on_file_write_complete_linux
```c
static void on_file_io_complete_linux( FILE_LINUX_IO* io);
static void on_file_write_complete_linux( FILE_LINUX_WRITE* write_info);
```
`on_file_io_complete_linux` is called when a file operation completes asynchronously.
`on_file_write_complete_linux` is called when an asynchronous write operation completes.
**SRS_FILE_LINUX_43_021: [** `on_file_io_complete_linux` shall recover the `aiocb` struct that was used to create the current asynchronous operation. **]**
**SRS_FILE_LINUX_43_021: [** `on_file_write_complete_linux` shall recover the `aiocb` struct that was used to create the current asynchronous write operation. **]**
**SRS_FILE_LINUX_43_022: [** `on_file_io_complete_linux` shall call `aio_return` to determine if the asynchronous operation succeeded. **]**
**SRS_FILE_LINUX_43_022: [** `on_file_write_complete_linux` shall call `aio_return` to determine if the asynchronous write operation succeeded. **]**
**SRS_FILE_LINUX_43_023: [** If the asynchronous operation did not succeed, `on_file_io_complete_linux` shall call `user_callback` with `false` as `is_successful`. **]**
**SRS_FILE_LINUX_43_023: [** If the asynchronous write operation did not succeed, `on_file_io_complete_linux` shall call `user_callback` with `user_context` and `false` as `is_successful`. **]**
**SRS_FILE_LINUX_43_024: [** If the type of the asynchronous operation is read, `on_file_io_complete_linux` shall construct a `CONSTBUFFER_HANDLE` by calling `CONSTBUFFER_CreateWithMoveMemory` from the bytes read by `ReadFile`. **]**
**SRS_FILE_LINUX_43_027: [** If the asynchronous write operation succeeded, `on_file_write_complete_linux` shall call `user_callback` with `user_context` and `true` as `is_successful`. **]**
**SRS_FILE_LINUX_43_025: [** If the construction of the `CONSTBUFFER_HANDLE` fails, `on_file_io_complete_linux` shall call `user_callback` with `user_context`, `false` as `is_successful` and `NULL` as `content`. **]**
## on_file_read_complete_linux
**SRS_FILE_LINUX_43_026: [** If the construction of the `CONSTBUFFER_HANDLE` succeeds, `on_file_io_complete_linux` shall call `user_callback` with `user_context`, `true` as `is_successful` and the created `CONSTBUFFER_HANDLE` as `content`. **]**
```c
static void on_file_read_complete_linux( FILE_LINUX_READ* read_info);
```
**SRS_FILE_LINUX_43_027: [** If the type of the asynchronous operation is write, `on_file_io_complete_linux` shall call `user_callback` with `user_context` and `true` as `is_successful`. **]**
**SRS_FILE_LINUX_43_039: [** `on_file_read_complete_linux` shall recover the `aiocb` struct that was used to create the current asynchronous read operation. **]**
**SRS_FILE_LINUX_43_028: [** If the type of asynchronous operation is neither read nor write, `on_file_io_complete_win32` shall call `user_report_fault_callback` with `user_report_fault_context` which were specified when `file_create` was called. **]**
**SRS_FILE_LINUX_43_040: [** `on_file_read_complete_linux` shall call `aio_return` to determine if the asynchronous read operation succeeded. **]**
**SRS_FILE_LINUX_43_041: [** If the asynchronous read operation did not succeed, `on_file_io_complete_linux` shall call `user_callback` with `user_context`, `false` as `is_successful` and the `CONSTBUFFER_HANDLE` from `read_info`. **]**
**SRS_FILE_LINUX_43_042: [** If the asynchronous read operation succeeded, `on_file_read_complete_linux` shall call `user_callback` with `user_context`, `false` as `is_successful` and the `CONSTBUFFER_HANDLE` from `read_info`. **]**

Просмотреть файл

@ -13,11 +13,17 @@ typedef struct FILE_HANDLE_DATA_TAG
void* user_report_fault_context;
}FILE_HANDLE_DATA;
typedef struct FILE_LINUX_IO_TAG
typedef struct FILE_LINUX_WRITE_TAG
{
void* handle;
FILE_ASYNC_OPERATION type;
FILE_IO_DATA data;
}FILE_LINUX_IO;
FILE_HANDLE_DATA handle;
FILE_WRITE_DATA_CONTEXT write_data;
}FILE_LINUX_WRITE;
static void on_file_io_complete_linux( FILE_LINUX_IO* io);
typedef struct FILE_LINUX_READ_TAG
{
FILE_HANDLE_DATA handle;
FILE_READ_DATA_CONTEXT read_data;
}FILE_LINUX_READ;
static void on_file_write_complete_linux( FILE_LINUX_WRITE* write_info);
static void on_file_read_complete_linux( FILE_LINUX_READ* read_info);

Просмотреть файл

@ -1,11 +1,13 @@
#Copyright (C) Microsoft Corporation. All rights reserved.
set(pal_win32_h_files
${pal_common_h_files}
inc/execution_engine_win32.h
inc/refcount_os.h
)
set(pal_win32_c_files
${pal_common_c_files}
src/execution_engine_win32.c
src/async_socket_win32.c
src/threadpool_win32.c
@ -26,9 +28,11 @@ FILE(GLOB pal_win32_md_files "devdoc/*.md")
SOURCE_GROUP(devdoc FILES ${pal_win32_md_files})
include_directories(${CMAKE_CURRENT_LIST_DIR}/inc)
include_directories(../common/inc)
add_library(pal_win32 ${pal_win32_h_files} ${pal_win32_c_files} ${pal_win32_md_files})
target_link_libraries(pal_win32 pal_interfaces pal_common pal_internal ws2_32 synchronization rpcrt4 azure_c_logging)
target_link_libraries(pal_win32 pal_interfaces pal_internal ws2_32 synchronization rpcrt4 azure_c_logging)
target_include_directories(pal_win32 PUBLIC ${CMAKE_CURRENT_LIST_DIR}/inc)
add_subdirectory(tests)
add_subdirectory(../common/tests common/tests)

Просмотреть файл

@ -27,11 +27,14 @@ typedef void(*FILE_REPORT_FAULT)(void* user_report_fault_context, const char* in
typedef void(*FILE_WRITE_CB)(void* user_context, bool is_successful);
typedef void(*FILE_READ_CB)(void* user_context, bool is_successful, CONSTBUFFER_HANDLE content);
MOCKABLE_FUNCTION(, FILE_HANDLE, file_create, EXECUTION_ENGINE_HANDLE, execution_engine, const char*, full_file_name, FILE_REPORT_FAULT, user_report_fault_callback, void*, user_report_fault_context);
MOCKABLE_FUNCTION(, void, file_destroy, FILE_HANDLE, handle);
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_WRITE_ASYNC_RESULT, file_write_async, FILE_HANDLE, handle, CONSTBUFFER_HANDLE, source, uint64_t, position, FILE_WRITE_CB, user_callback, void*, user_context)(0, MU_FAILURE);
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_READ_ASYNC_RESULT, file_read_async, FILE_HANDLE, handle, uint32_t, size, uint64_t, position, FILE_READ_CB, user_callback, void*, user_context)(0, MU_FAILURE);
MOCKABLE_FUNCTION_WITH_RETURNS(, int, file_extend_filesize, FILE_HANDLE, handle, uint64_t, desired_size, bool, has_manage_volume)(0, MU_FAILURE);
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_WRITE_ASYNC_RESULT, file_write_async, FILE_HANDLE, handle, CONSTBUFFER_HANDLE, source, uint64_t, position, FILE_WRITE_CB, user_callback, void*, user_context)(FILE_WRITE_ASYNC_OK, FILE_WRITE_ASYNC_ERROR);
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_READ_ASYNC_RESULT, file_read_async, FILE_HANDLE, handle, uint32_t, size, uint64_t, position, FILE_READ_CB, user_callback, void*, user_context)(FILE_READ_ASYNC_OK, FILE_READ_ASYNC_ERROR);
MOCKABLE_FUNCTION_WITH_RETURNS(, int, file_extend, FILE_HANDLE, handle, uint64_t, desired_size, bool, has_manage_volume)(0, MU_FAILURE);
```
## file_create
@ -42,15 +45,15 @@ MOCKABLE_FUNCTION(, FILE_HANDLE, file_create, EXECUTION_ENGINE_HANDLE, execution
**SRS_FILE_WIN32_43_040: [** If `execution_engine` is `NULL`, `file_create` shall fail and return `NULL`. **]**
**SRS_FILE_WIN32_43_041: [** If `full_file_name` is `NULL` then `file_create` shall fail and return `NULL`. **]**
**SRS_FILE_WIN32_43_001: [** `file_create` shall call `CreateFileA` with `full_file_name` as `lpFileName`, `GENERIC_READ|GENERIC_WRITE` as `dwDesiredAccess`, `FILE_SHARED_READ` as `dwShareMode`, `NULL` as `lpSecurityAttributes`, `OPEN_ALWAYS` as `dwCreationDisposition`, `FILE_FLAG_OVERLAPPED|FILE_FLAG_WRITE_THROUGH` as `dwFlagsAndAttributes` and `NULL` as `hTemplateFiles`. **]**
**SRS_FILE_WIN32_43_048: [** If `full_file_name` is `NULL` then `file_create` shall fail and return `NULL`. **]**
**SRS_FILE_WIN32_43_041: [** `file_create` shall allocate a `FILE_HANDLE`. **]**
**SRS_FILE_WIN32_43_001: [** `file_create` shall call `CreateFileA` with `full_file_name` as `lpFileName`, `GENERIC_READ|GENERIC_WRITE` as `dwDesiredAccess`, `FILE_SHARED_READ` as `dwShareMode`, `NULL` as `lpSecurityAttributes`, `OPEN_ALWAYS` as `dwCreationDisposition`, `FILE_FLAG_OVERLAPPED|FILE_FLAG_WRITE_THROUGH` as `dwFlagsAndAttributes` and `NULL` as `hTemplateFiles`. **]**
**SRS_FILE_WIN32_43_002: [** `file_create` shall call `SetFileCompletionNotificationModes` to disable calling the completion port when an async operations finishes synchrounously. **]**
**SRS_FILE_WIN32_43_003: [** `file_create` shall initialize a threadpool environment. **]**
**SRS_FILE_WIN32_43_003: [** `file_create` shall allocate a threadpool environment. **]**
**SRS_FILE_WIN32_43_004: [** `file_create` shall obtain a `PTP_POOL` struct by calling `execution_engine_win32_get_threadpool` on `execution_engine`. **]**
@ -60,11 +63,11 @@ MOCKABLE_FUNCTION(, FILE_HANDLE, file_create, EXECUTION_ENGINE_HANDLE, execution
**SRS_FILE_WIN32_43_007: [** `file_create` shall register the cleanup group with the threadpool environment. **]**
**SRS_FILE_WIN32_43_033: [** `file_create` shall create a threadpool io and use `on_file_io_complete_win32` as a callback. **]**
**SRS_FILE_WIN32_43_033: [** `file_create` shall create a threadpool io with the allocated `FILE_HANDLE` and `on_file_io_complete_win32` as a callback. **]**
**SRS_FILE_WIN32_43_008: [** If there are any failures, `file_create` shall return `NULL`. **]**
**SRS_FILE_WIN32_43_009: [** `file_create` shall succeed and return the file handle of the opened file. **]**
**SRS_FILE_WIN32_43_009: [** `file_create` shall succeed and return a non-`NULL` value. **]**
## file_destroy
@ -72,7 +75,7 @@ MOCKABLE_FUNCTION(, FILE_HANDLE, file_create, EXECUTION_ENGINE_HANDLE, execution
MOCKABLE_FUNCTION(, void, file_destroy, FILE_HANDLE, handle);
```
**SRS_FILE_WIN32_43_042: [** If `handle` is `NULL`, `file_destroy` shall return. **]**
**SRS_FILE_WIN32_43_049: [** If `handle` is `NULL`, `file_destroy` shall return. **]**
**SRS_FILE_WIN32_43_011: [** `file_destroy` shall wait for all I/O to complete. **]**
@ -80,17 +83,17 @@ MOCKABLE_FUNCTION(, void, file_destroy, FILE_HANDLE, handle);
**SRS_FILE_WIN32_43_013: [** `file_destroy` shall destroy the environment. **]**
**SRS_FILE_WIN32_43_015: [** `file_destroy` shall close the threadpool IO. **]**
**SRS_FILE_WIN32_43_016: [** `file_destroy` shall call `CloseHandle` on `handle` **]**
**SRS_FILE_WIN32_43_015: [** `file_destroy` shall close the threadpool IO. **]**
**SRS_FILE_WIN32_43_042: [** `file_destroy` shall free the `FILE_HANDLE`. **]**
## file_write_async
```c
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_WRITE_ASYNC_RESULT, file_write_async, FILE_HANDLE, handle, CONSTBUFFER_HANDLE, source, uint64_t, position, FILE_WRITE_CB, user_callback, void*, user_context)(0, MU_FAILURE);
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_WRITE_ASYNC_RESULT, file_write_async, FILE_HANDLE, handle, CONSTBUFFER_HANDLE, source, uint64_t, position, FILE_WRITE_CB, user_callback, void*, user_context)(FILE_WRITE_ASYNC_OK, FILE_WRITE_ASYNC_ERROR);
```
**SRS_FILE_WIN32_43_043: [** If `handle` is `NULL` then `file_write_async` shall fail and return `FILE_WRITE_ASYNC_INVALID_ARGS`. **]**
@ -101,22 +104,22 @@ MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_WRITE_ASYNC_RESULT, file_write_async, FILE
**SRS_FILE_WIN32_43_017: [** `file_write_async` shall call `StartThreadpoolIo`. **]**
**SRS_FILE_WIN32_43_018: [** `file_write_async` shall allocate a context to store `handle`, write as the type of asyncronous operation, `source`, `user_callback` and `user_context. **]**
**SRS_FILE_WIN32_43_020: [** `file_write_async` shall allocate an `OVERLAPPED` struct and populate it with an event and `position`. **]**
**SRS_FILE_WIN32_43_020: [** `file_write_async` shall populate the `ov` field of the `FILE_WIN32_IO` using `position`. **]**
**SRS_FILE_WIN32_43_018: [** `file_write_async` shall allocate a context to store the allocated `OVERLAPPED` struct, `handle`, write as the type of asynchronous operation, `source`, `user_callback` and `user_context`. **]**
**SRS_FILE_WIN32_43_021: [** `file_write_async` shall call `WriteFile`. **]**
**SRS_FILE_WIN32_43_021: [** `file_write_async` shall call `WriteFile` with `handle`, `source` and the allocated `OVERLAPPED` struct. **]**
**SRS_FILE_WIN32_43_022: [** If `WriteFile` fails synchronously and `GetLastError` indicates `ERROR_IO_PENDING` then `file_write_async` shall succeed and return `FILE_WRITE_ASYNC_OK`. **]**
**SRS_FILE_WIN32_43_023: [** If `WriteFile` fails synchronously and `GetLastError` does not indicate `ERROR_IO_PENDING` then `file_write_async` shall fail, call `CancelThreadpoolIo` and return `FILE_WRITE_ASYNC_WRITE_ERROR`. **]**
**SRS_FILE_WIN32_43_024: [** If `WriteFile` succeeds synchronously then `file_write_async` shall succeed, call `CancelThreadpoolIo` and `user_callback` and return `FILE_WRITE_ASYNC_OK`. **]**
**SRS_FILE_WIN32_43_024: [** If `WriteFile` succeeds synchronously then `file_write_async` shall succeed, call `CancelThreadpoolIo`, call `user_callback` and return `FILE_WRITE_ASYNC_OK`. **]**
## file_read_async
```c
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_READ_ASYNC_RESULT, file_read_async, FILE_HANDLE, handle, uint32_t, size, uint64_t, position, FILE_READ_CB, user_callback, void*, user_context)(0, MU_FAILURE);
MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_READ_ASYNC_RESULT, file_read_async, FILE_HANDLE, handle, uint32_t, size, uint64_t, position, FILE_READ_CB, user_callback, void*, user_context)(FILE_READ_ASYNC_OK, FILE_READ_ASYNC_ERROR);
```
**SRS_FILE_WIN32_43_046: [** If `handle` is `NULL` then `file_read_async` shall fail and return `FILE_READ_ASYNC_INVALID_ARGS`. **]**
@ -125,9 +128,13 @@ MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_READ_ASYNC_RESULT, file_read_async, FILE_H
**SRS_FILE_WIN32_43_025: [** `file_read_async` shall call `StartThreadpoolIo`. **]**
**SRS_FILE_WIN32_43_026: [** `file_read_async` shall allocate a context to store `handle`, read as the type of asynchronous operation, `user_callback` and `user_context` **]**
**SRS_FILE_WIN32_43_028: [** `file_read_async` shall allocate an `OVERLAPPED` struct and populate it with an event and `position`. **]**
**SRS_FILE_WIN32_43_028: [** `file_read_async` shall populate the `ov` field of the `FILE_WIN32_IO` using `position`. **]**
**SRS_FILE_WIN32_43_051: [** `file_read_async` shall allocate a buffer of size `size`. **]**
**SRS_FILE_WIN32_43_052: [** `file_read_async` shall create a `CONSTBUFFER_HANDLE` using the allocated buffer. **]**
**SRS_FILE_WIN32_43_026: [** `file_read_async` shall allocate a context to store the allocated `OVERLAPPED` struct, the created `CONSTBUFFER_HANDLE`, `handle`, read as the type of asynchronous operation, `user_callback` and `user_context` **]**
**SRS_FILE_WIN32_43_029: [** `file_read_async` shall call `ReadFile`. **]**
@ -135,8 +142,15 @@ MOCKABLE_FUNCTION_WITH_RETURNS(, FILE_READ_ASYNC_RESULT, file_read_async, FILE_H
**SRS_FILE_WIN32_43_031: [** If `ReadFile` fails synchronously and `GetLastError` does not indicate `ERROR_IO_PENDING` then `file_read_async` shall fail, call `CancelThreadpoolIo` and return `FILE_READ_ASYNC_WRITE_ERROR`. **]**
**SRS_FILE_WIN32_43_032: [** If `ReadFile` succeeds synchronously then `file_read_async` shall succeed, call `CancelThreadpoolIo` and `user_callback` and return `FILE_READ_ASYNC_OK`. **]**
**SRS_FILE_WIN32_43_032: [** If `ReadFile` succeeds synchronously then `file_read_async` shall succeed, call `CancelThreadpoolIo`, call `user_callback` and return `FILE_READ_ASYNC_OK`. **]**
## file_extend
```c
MOCKABLE_FUNCTION_WITH_RETURNS(, int, file_extend, FILE_HANDLE, handle, uint64_t, desired_size, bool, has_manage_volume)(0, MU_FAILURE);
```
**SRS_FILE_WIN32_43_050: [** `file_extend` shall return `0`. **]**
## on_file_io_complete_win32

Просмотреть файл

@ -19,6 +19,12 @@ typedef struct FILE_HANDLE_DATA_TAG
}FILE_HANDLE_DATA;
typedef union FILE_IO_DATA_TAG
{
FILE_READ_DATA_CONTEXT read_data;
FILE_WRITE_DATA_CONTEXT write_data;
}FILE_IO_DATA;
typedef struct FILE_WIN32_IO_TAG
{
OVERLAPPED ov;

Просмотреть файл

@ -17,7 +17,7 @@ set(${theseTestsName}_h_files
../../../interfaces/inc/async_socket.h
)
build_c_tests(${theseTestsName} ON "tests/azure_c_pal/win32" ADDITIONAL_LIBS pal_interfaces pal_common synchronization ws2_32)
build_c_tests(${theseTestsName} ON "tests/azure_c_pal/win32" ADDITIONAL_LIBS pal_interfaces synchronization ws2_32)
set_target_properties(${theseTestsName}_exe PROPERTIES LINK_FLAGS "/ignore:4217")
if(use_cppunittest)

Просмотреть файл

@ -18,7 +18,7 @@ set(${theseTestsName}_h_files
../../../interfaces/inc/execution_engine.h
)
build_c_tests(${theseTestsName} ON "tests/azure_c_pal/win32" ADDITIONAL_LIBS pal_interfaces pal_common)
build_c_tests(${theseTestsName} ON "tests/azure_c_pal/win32" ADDITIONAL_LIBS pal_interfaces)
set_target_properties(${theseTestsName}_exe PROPERTIES LINK_FLAGS "/ignore:4217")
if(use_cppunittest)

Просмотреть файл

@ -17,4 +17,4 @@ set(${theseTestsName}_h_files
../../../interfaces/inc/lock.h
)
build_c_tests(${theseTestsName} ON "tests/azure_c_pal/win32" ADDITIONAL_LIBS pal_interfaces pal_common)
build_c_tests(${theseTestsName} ON "tests/azure_c_pal/win32" ADDITIONAL_LIBS pal_interfaces)

Просмотреть файл

@ -19,4 +19,4 @@ set(${theseTestsName}_c_files
set(${theseTestsName}_h_files
)
build_c_tests(${theseTestsName} ON "tests/azure_c_pal/win32" ADDITIONAL_LIBS pal_common)
build_c_tests(${theseTestsName} ON "tests/azure_c_pal/win32" ADDITIONAL_LIBS pal_interfaces)

Просмотреть файл

@ -20,5 +20,5 @@ set(${theseTestsName}_cpp_files
set(${theseTestsName}_h_files
)
build_c_tests(${theseTestsName} ON "tests/azure_c_pal/win32" ADDITIONAL_LIBS pal_interfaces pal_common)
build_c_tests(${theseTestsName} ON "tests/azure_c_pal/win32" ADDITIONAL_LIBS pal_interfaces)

Просмотреть файл

@ -16,4 +16,4 @@ set(${theseTestsName}_cpp_files
set(${theseTestsName}_h_files
)
build_c_tests(${theseTestsName} ON "tests/azure_c_pal/win32" ADDITIONAL_LIBS pal_interfaces pal_common pal_win32)
build_c_tests(${theseTestsName} ON "tests/azure_c_pal/win32" ADDITIONAL_LIBS pal_interfaces pal_win32)

Просмотреть файл

@ -19,7 +19,7 @@ set(${theseTestsName}_h_files
../../../interfaces/inc/string_utils.h
)
build_c_tests(${theseTestsName} ON "tests/azure_c_pal/win32" ADDITIONAL_LIBS pal_interfaces pal_common synchronization)
build_c_tests(${theseTestsName} ON "tests/azure_c_pal/win32" ADDITIONAL_LIBS pal_interfaces synchronization)
set_target_properties(${theseTestsName}_exe PROPERTIES LINK_FLAGS "/ignore:4217")
if(use_cppunittest)

Просмотреть файл

@ -16,4 +16,4 @@ set(${theseTestsName}_c_files
set(${theseTestsName}_h_files
)
build_c_tests(${theseTestsName} ON "tests/azure_c_pal/win32" ADDITIONAL_LIBS pal_interfaces pal_common)
build_c_tests(${theseTestsName} ON "tests/azure_c_pal/win32" ADDITIONAL_LIBS pal_interfaces)